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.
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 109 + 7.
Two sequences are considered different if at least one element differs from each other.
classSolution { int dp[6][16][5001]; int mod = 1e9 + 7; inthelper(int n, int con, int num, vector<int>& ma){ if(n == 0) return1; int& res = dp[num][con][n]; if(res != -1) return res; res = 0; for(int i = 0; i < 6; i++) { if(i == num and ma[num] == con) continue; res = (res + helper(n-1, i == num ? con + 1 : 1, i, ma)) % mod; } return res; } public: intdieSimulator(int n, vector<int>& rollMax){ memset(dp,-1,sizeof dp); int res = 0; for(int i = 0; i < 6; i++) { res = (res + helper(n-1, 1, i, rollMax)) % mod; } return res; } };