#K6441. Count Ways to Achieve Target Balance

    ID: 31969 Type: Default 1000ms 256MiB

Count Ways to Achieve Target Balance

Count Ways to Achieve Target Balance

You are given three integers: a target balance \(T\), a minimum transaction amount \(m\), and a maximum transaction amount \(M\). Each transaction is an integer in the inclusive range \([m, M]\). A sequence of transactions is valid if the sum of its transactions is exactly \(T\). Note that you may use zero or more transactions; however, by convention, there is exactly one way to achieve a target balance of 0 (by performing no transactions).

Your task is to count the number of different sequences of transactions (order matters) that will result in the target balance \(T\>. It is guaranteed that \(T \ge 0\). This problem can be solved using dynamic programming.

Input: Three space-separated integers representing \(T\), \(m\) and \(M\).
Output: A single integer, the number of ways to achieve the balance \(T\>.

inputFormat

The input consists of a single line with three integers:

  • T (target balance, \(T \ge 0\))
  • m (minimum transaction amount)
  • M (maximum transaction amount)

They are separated by spaces.

outputFormat

Output a single integer representing the number of possible sequences of transactions that sum exactly to \(T\>.

## sample
5 -2 3
13