-
Notifications
You must be signed in to change notification settings - Fork 8
/
coin_change_dp.cpp
51 lines (48 loc) · 1.26 KB
/
coin_change_dp.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
/*
* Classical Coin Change Problem
* Question Example:https://www.hackerearth.com/practice/algorithms/dynamic-programming/introduction-to-dynamic-programming-1/practice-problems/algorithm/accomodation-a5c006f3/
* References: GFG + https://www.youtube.com/watch?v=jaNZ83Q3QGc
* */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mkp(a,b) make_pair(a,b)
#define eb emplace_back
#define mod (long long)(1e9+7)
#define FILE_READ freopen("input.txt","r",stdin)
#define FILE_WRITE freopen("output.txt","w",stdout)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long ul;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// FILE_READ;
// FILE_WRITE;
int m,n;
cin>>m>>n;
int a[m];
for(int i=0;i<m;++i)
{
cin>>a[i];
}
int dp[n+1]={0};
dp[0]=1;
for(int i=0;i<m;++i)
{
for(int j=1;j<=n;++j)
{
if(j<a[i]) continue;
dp[j]+=dp[j-a[i]];
}
}
cout<<dp[n];
return 0;
}