-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoin Combinations II.cpp
56 lines (50 loc) · 1.29 KB
/
Coin Combinations II.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
#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(v) (v).begin(), (v).end()
#define fl fflush(stdout)
void solve() {
int mod = 1e9 + 7;
int n, k; cin >> n >> k;
vector<int> val(n);
for (int i = 0; i < n; i++) cin >> val[i];
vector<int> dp(k + 1, 0);
dp[0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 1; j <= k; j++) {
if (j - val[i] >= 0) {
dp[j] = (dp[j] % mod + dp[j - val[i]] % mod) % mod;
}
}
}
cout << dp[k];
}
signed main() {
auto start = high_resolution_clock::now();
IOS;
int t = 1;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r" , stdin);
freopen("output.txt", "w", stdout);
#endif
// cin >> t;
int i = 1;
while (t--) {
// cout << "CASE #" << i << ": ";
solve();
cout << endl;
i++;
}
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
cerr << "Time taken:" << duration.count() / 1000000.0 << " seconds" << "\n";
return 0;
}