forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1223.cpp
More file actions
28 lines (27 loc) · 737 Bytes
/
1223.cpp
File metadata and controls
28 lines (27 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Solution
{
public:
int dieSimulator(int n, vector<int>& rollMax)
{
int dp[6][16], tmp[6], mod = 1e9 + 7;
memset(dp, 0, sizeof dp);
for (int i = 0; i < 6; i++) tmp[i] = dp[i][1] = 1;
int res = 6, ts;
for (int i = 1; i < n; i++)
{
ts = 0;
for (int j = 0; j < 6; j++)
{
dp[j][0] = ((res - tmp[j])%mod + mod)%mod;
tmp[j] = 0;
for (int k = rollMax[j]; k > 0; k--)
{
tmp[j] = (tmp[j] + (dp[j][k] = dp[j][k-1])) % mod;
}
ts = (ts + tmp[j])%mod;
}
res = ts;
}
return res;
}
};