File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+
3
+ #include < bits/stdc++.h>
4
+ #define ll long long
5
+ #define ull unsigned long long
6
+ #define endl ' \n '
7
+ #define pb push_back
8
+ #define mp make_pair
9
+ #define sp (x ) fixed<<setprecision(x)
10
+ #define p_q priority_queue
11
+ #define fast_io ios_base::sync_with_stdio (false );cin.tie(NULL );cout.tie(NULL );
12
+ using namespace std ;
13
+
14
+ int main ()
15
+ {
16
+ fast_io;
17
+
18
+ ll n,x;
19
+
20
+ cin>>x>>n;
21
+
22
+ vector <ll> coin (n);
23
+ for (ll&i : coin)
24
+ cin>>i;
25
+
26
+ vector <ll> dp (x+1 ,0 );
27
+ dp[0 ] = 1 ; // ways to achieve sum of 0,using the array = 1, i.e = taking a null subset.
28
+
29
+ for (ll i=0 ;i<n;i++)// we take each coin specifically, and do the needed calculations
30
+ {
31
+ for (ll j=0 ;j<=x;j++)// we build numbers from 0 to sum, using the taken coin i.e- coin[i]
32
+ {
33
+ if (j-coin[i] >= 0 )
34
+ {
35
+ dp[j] += dp[j-coin[i]];
36
+
37
+ }
38
+ }
39
+ }
40
+ cout<<dp[x]<<endl;
41
+
42
+ return 0 ;
43
+ }
You can’t perform that action at this time.
0 commit comments