Back to course home
0% completed
Vote For New Content
Number of Dice Rolls With Target Sum (medium)
Problem Statement
You are given n
dice, each dice having k
faces numbered from 1
to k
. You are also given target
positive integer.
Return the number of ways you can roll the dice so that the sum
of the face-up
numbers equals the target
sum. Since the answer may be too large, return it modulo 10<sup>9</sup> + 7.
Examples
Example 1
- Input: n = 2, k = 4, target = 5
- Expected Output: 4
- Justification: The possible rolls are (1, 4), (2, 3), (3, 2), and (4, 1).
Example 2
- Input: n = 3, k = 6, target = 8
- Expected Output: 21
- Justification: There are 21 combinations of rolling three dice with faces from 1 to 6 that sum up to 8.
Example 3
- Input: n = 1, k = 2, target = 2
- Expected Output: 1
- Justification: The only possible roll is (2).
Constraints:
1 <= n, k <= 30
1 <= target <= 1000
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page
Problem Statement
Examples
Try it yourself