forked from aayushi1499/Hacktoberfest2021-DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoin_change_dp.cpp
58 lines (50 loc) · 990 Bytes
/
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
52
53
54
55
56
57
58
#include<bits/stdc++.h>
using namespace std;
class Solution
{
public:
long long int count( int S[], int m, int n )
{
//code here.
long long int t[m+1][n+1];
for(int i=0;i<=m;i++)
{
t[i][0] = 1;
}
for(int j=1;j<=n;j++)
{
t[0][j] = 0;
}
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
if(S[i-1]<=j)
{
t[i][j] = t[i-1][j] + t[i][j-S[i-1]];
}
else
{
t[i][j] = t[i-1][j];
}
}
}
return t[m][n];
}
};
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
int arr[m];
for(int i=0;i<m;i++)
cin>>arr[i];
Solution ob;
cout<<ob.count(arr,m,n)<<endl;
}
return 0;
}