1223. Dice Roll Simulation Hard

@problem@discussion
#Array#Dynamic Programming



1/**
2 * [1223] Dice Roll Simulation
3 *
4 * A die simulator generates a random number from 1 to 6 for each roll. You introduced a constraint to the generator such that it cannot roll the number i more than rollMax[i] (1-indexed) consecutive times.
5 * Given an array of integers rollMax and an integer n, return the number of distinct sequences that can be obtained with exact n rolls. Since the answer may be too large, return it modulo 10^9 + 7.
6 * Two sequences are considered different if at least one element differs from each other.
7 *  
8 * Example 1:
9 * 
10 * Input: n = 2, rollMax = [1,1,2,2,2,3]
11 * Output: 34
12 * Explanation: There will be 2 rolls of die, if there are no constraints on the die, there are 6 * 6 = 36 possible combinations. In this case, looking at rollMax array, the numbers 1 and 2 appear at most once consecutively, therefore sequences (1,1) and (2,2) cannot occur, so the final answer is 36-2 = 34.
13 * 
14 * Example 2:
15 * 
16 * Input: n = 2, rollMax = [1,1,1,1,1,1]
17 * Output: 30
18 * 
19 * Example 3:
20 * 
21 * Input: n = 3, rollMax = [1,1,1,2,2,3]
22 * Output: 181
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	1 <= n <= 5000
28 * 	rollMax.length == 6
29 * 	1 <= rollMax[i] <= 15
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/dice-roll-simulation/
35// discuss: https://leetcode.com/problems/dice-roll-simulation/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn die_simulator(n: i32, roll_max: Vec<i32>) -> i32 {
41        0
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_1223() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.