-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCoin Change.cpp
More file actions
43 lines (39 loc) · 763 Bytes
/
Copy pathCoin Change.cpp
File metadata and controls
43 lines (39 loc) · 763 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
//{ Driver Code Starts
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution
{
public:
long long int count(int S[], int m, int n)
{
vector<long long int> dp(n + 1, 0);
dp[0] = 1;
for (int i = 0; i < m; i++)
{
for (int j = S[i]; j <= n; j++)
{
dp[j] += dp[j - S[i]];
}
}
return dp[n];
}
};
//{ Driver Code Starts.
int main()
{
int t;
cin >> t;
while (t--)
{
int sum, N;
cin >> sum >> N;
int coins[N];
for (int i = 0; i < N; i++)
cin >> coins[i];
Solution ob;
cout << ob.count(coins, N, sum) << endl;
}
return 0;
}
// } Driver Code Ends