-
Notifications
You must be signed in to change notification settings - Fork 1
/
coin_combinations_1.cpp
82 lines (73 loc) · 1.76 KB
/
coin_combinations_1.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
//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
#define sz(x) ((long long)(x).size())
#define all(x) x.begin(),x.end()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007 //1e9+7
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<int,int>
#define tt ll t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m; while(b>0) { if(b&1) ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
bool cmp(pair<string,int>p1,pair<string,int>p2) {
return p1.ss > p2.ss;
}
const int MAXN = 5 * 1000000 + 10; // 1e6
ll dp[MAXN];
int ddp(int n,vector<int>&coins) {
if(n==0) {
return dp[n]=1;
}
if(n<0) {
return 0;
}
if(dp[n] != -1) {
return dp[n];
}
ll ways = 0;
for (auto i : coins) {
ways = ((ways%mod)+(ddp(n - i,coins)%mod))%mod;
}
return dp[n]=ways;
}
int32_t main() {
fio
int x,n;
cin >> x >> n;
vector<int>coins(x);
for (int j = 0; j < x; ++j) {
cin >> coins[j];
}
for (long long & i : dp) {
i = -1;
}
ddp(n,coins);
cout << dp[n] << endl;
}