Problem 644
Number of Dice Rolls With Target Sum
Medium · 20 pts · Dynamic Programming
Problem
You roll N dice, each with K faces numbered 1 to K. Count the ways to roll them so that the sum of the faces equals TARGET. The dice are distinguishable, so rolling 1 then 6 and rolling 6 then 1 are different ways. Print the count modulo 1000000007. Let ways[i][s] be the number of ways for the first i dice to sum to s; each new die adds a face from 1 to K. Keep the counts in a 64-bit integer type (long long in C++, long in Java) and take the remainder after every addition and multiplication: adding or multiplying two remainders can be larger than a 32-bit int can hold (Python needs nothing special).
Input
A single line with N, K and TARGET.
Output
Print the number of ways modulo 1000000007.
Constraints
1 <= N, K <= 30; 1 <= TARGET <= 1000
Example input
2 6 7
Example output
6
Explanation
With 2 dice of 6 faces and target 7, the rolls (1,6), (2,5), (3,4), (4,3), (5,2) and (6,1) all sum to 7. So there are 6 ways.