-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathDice Combinations.cpp
88 lines (68 loc) · 2.04 KB
/
Dice Combinations.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Solution by Rahul Surana
***********************************************************
Your task is to count the number of ways to construct sum n by throwing a dice one or more times. Each throw produces an outcome between 1 and 6.
For example, if n=3, there are 4 ways:
1+1+1
1+2
2+1
3
Input
The only input line has an integer n.
Output
Print the number of ways modulo 109+7.
***********************************************************
*/
#include <bits/stdc++.h>
#define ll long long
#define vl vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define all(a) a.begin(),a.end()
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define trace2(x,y) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<" | "<<#z<<" : "<<z<<endl;
#define fast_io std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int MOD=1e9+7;
vector<ll> dp;
ll df(ll s, ll n){
if(s > n) return 0;
if(s==n) return 1;
if(dp[s] != -1) return dp[s]%MOD;
cout << s <<" ";
ll ans = 0;
for(int i = 1; i <= 6; i++){
ans = (ans%MOD + df(s+i,n)%MOD)%MOD;
}
return dp[s] = ans%MOD;
}
int main() {
fast_io;
int t=1,w = 1;
// cin >> t;
while(t >= (w)){
ll n;
cin >> n;
dp.resize(n+1,0);
dp[1] = 1;
dp[0] = 1;
// for(int i = 1; i < 7; i++) dp[i] = 1;
for(int i = 2; i <= n; i++){
for(int j = 1; j <=6; j++){
if(i-j >= 0)
dp[i] = (dp[i]%MOD + dp[i-j]%MOD)%MOD;
}
// cout << dp[i] <<" ";
}
cout << dp[n]%MOD <<"\n";
// cout << "Case #" << w << ": " << ans <<"\n";
w++;
}
}