


As the answer can be large, return your answer modulo 10^9 + 7.
Can you solve this using not more than O(S) extra space?
The first line of input contains an integer T denoting the number of test cases.
The first and the only line of every test case contains 3 integers D, F and S representing the number of dices, the number of faces on each die and the target sum respectively.
For each test case, print the number of ways to get the sum S in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= D, F <= 50
1 <= S <= 10^3
Time limit: 1 sec
Suppose we have 3 dice each with 6 faces and we have to find the number of ways to achieve the sum 8.
The below figure shows some of the recursive calls are made for the given problem.
As we can see, some subproblems are called multiple times.
For example, the subproblem {1,6,5} is called 2 times, {1,6,3} is called 4 times and {1,6,1} is called 6 times.
That’s why we are storing the solved subproblems in a lookup table so that we don’t have to solve them again. Whenever a call is made to the solved subproblem, we will directly return the answer of that subproblem stored in the lookup table.
Approach:
Let us understand the above algorithm in detail with an example:
For the test case where D = 3, F = 6 and S = 4
The table will be:
We will notice:
DP[2][2] = DP[1][1] + DP[1][0]
DP[2][3] = DP[1][2] + DP[1][1] + DP[1][0]
DP[2][4] = DP[1][3] + DP[1][2] + DP[1][1] + DP[1][0]
The table becomes:
Similarly, the final table will be: