forked from garvit-bhardwaj/Leetcode-Problems-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiceRollSimulation.cpp
More file actions
54 lines (45 loc) · 1.23 KB
/
diceRollSimulation.cpp
File metadata and controls
54 lines (45 loc) · 1.23 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Solution {
public:
int dieSimulator(int n, vector<int>& rollMax) {
int dp[n][7][16];
int mo=1e9+7;
memset(dp,0,sizeof dp);
int i,j,k;
for(i=1;i<=6;i++)
{
dp[0][i][1]=1;
}
long long ans=0;
for(i=1;i<n;i++)
{
for(j=1;j<=6;j++)
{
for(k=1;k<=6;k++)
{
for(int z=1;z<=rollMax[j-1];z++)
{
int rolls=0;
if(j==k)
{
rolls=z+1;
}
else
rolls=1;
if(rolls<=rollMax[k-1])
{
dp[i][k][rolls]=(dp[i][k][rolls]+dp[i-1][j][z])%mo;
}
}
}
}
}
for(i=1;i<=6;i++)
{
for(j=1;j<=rollMax[i-1];j++)
{
ans=(ans+dp[n-1][i][j])%mo;
}
}
return ans;
}
};