-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoin_Combinations_II.cpp
More file actions
54 lines (45 loc) · 863 Bytes
/
Coin_Combinations_II.cpp
File metadata and controls
54 lines (45 loc) · 863 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
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
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
void solve()
{
// TLE
int n, x; cin >> n >> x;
vector<int> coins(n);
for(int i = 0;i < n; i++){
cin >> coins[i];
}
vector<vector<int>> dp(n+1, vector<int>(x+1));
for(int i = 0; i <n ;i++){
dp[i][0] = 1;
}
for(int i = n-1; i >=0; i--){
for(int j = 1; j <=x; j++){
int skip = dp[i+1][j];
int pick = 0;
if(coins[i] <= j){
pick = dp[i][j-coins[i]];
}
dp[i][j] = (skip + pick) % MOD;
}
}
cout << dp[0][x];
return;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r", stdin);
freopen("output.txt","w", stdout);
#endif
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// int T; cin>>T;
// cin.ignore(); // must be there when using getline(cin, s)
// while(T--){
// time(&start);
solve();
// }
return 0;
}