1155. Number of Dice Rolls With Target Sum Medium
1/**
2 * [1155] Number of Dice Rolls With Target Sum
3 *
4 * You have n dice and each die has k faces numbered from 1 to k.
5 * Given three integers n, k, and target, return the number of possible ways (out of the k^n total ways) to roll the dice so the sum of the face-up numbers equals target. Since the answer may be too large, return it modulo 10^9 + 7.
6 *
7 * Example 1:
8 *
9 * Input: n = 1, k = 6, target = 3
10 * Output: 1
11 * Explanation: You throw one die with 6 faces.
12 * There is only one way to get a sum of 3.
13 *
14 * Example 2:
15 *
16 * Input: n = 2, k = 6, target = 7
17 * Output: 6
18 * Explanation: You throw two dice, each with 6 faces.
19 * There are 6 ways to get a sum of 7: 1+6, 2+5, 3+4, 4+3, 5+2, 6+1.
20 *
21 * Example 3:
22 *
23 * Input: n = 30, k = 30, target = 500
24 * Output: 222616187
25 * Explanation: The answer must be returned modulo 10^9 + 7.
26 *
27 *
28 * Constraints:
29 *
30 * 1 <= n, k <= 30
31 * 1 <= target <= 1000
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/number-of-dice-rolls-with-target-sum/
37// discuss: https://leetcode.com/problems/number-of-dice-rolls-with-target-sum/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn num_rolls_to_target(n: i32, k: i32, target: i32) -> i32 {
43 0
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_1155() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.