Leetcode-5224 Dice Roll Simulation(掷骰子模拟)

 1 typedef pair<int,int> P;
 2 typedef long long ll;
 3 #define _for(i,a,b) for(register int i = (a);i < b;i ++)
 4 #define _rep(i,a,b) for(register int i = (a);i > b;i --)
 5 #define INF 0x3f3f3f3f
 6 #define MOD 1000000007
 7 #define maxn 10003
 8 #define pb push_back
 9 #define debug() printf("Miku Check OK!\n")
10 
11 
12 class Solution
13 {
14     public:
15         ll dp[7][16][5005];
16         int dieSimulator(int n, vector<int>& rollMax)
17         {
18             _for(i,1,7)
19                 dp[i][1][1] = 1;
20             
21             _for(i,2,n+1)
22                 _for(j,1,7)
23                 {
24                     _for(k,1,rollMax[j-1]+1)
25                         dp[j][k][i] += dp[j][k-1][i-1],
26                         dp[j][k][i] %= MOD;
27                     _for(k,1,7)
28                     {
29                         if(k==j)
30                             continue;
31                         _for(m,1,rollMax[k-1]+1)
32                             dp[j][1][i] += dp[k][m][i-1];
33                         dp[j][1][i] %= MOD;
34                     }
35                 }
36             ll ans = 0;
37             _for(i,1,7)
38                 _for(j,1,rollMax[i-1]+1)
39                     ans += dp[i][j][n],ans %= MOD;
40             return ans;
41         }
42 };

 

posted @ 2019-10-13 12:08  Asurudo  阅读(309)  评论(0编辑  收藏  举报