Skip to content

Commit 9e4a050

Browse files
committed
added coin combinations
1 parent 0762a37 commit 9e4a050

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

coinCombination1.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "bits/stdc++.h"
2+
using namespace std;
3+
#define ll long long
4+
#define mod 1000000007
5+
6+
void solve()
7+
{
8+
ll n,x;
9+
cin >> n >> x;
10+
vector<ll> coins(n);
11+
for(ll i=0; i<n; i++) cin >> coins[i];
12+
13+
vector<ll> dp(x+1, 0);
14+
dp[0] = 1;
15+
for(ll i=1; i<=x; i++)
16+
{
17+
for(ll coin: coins)
18+
{
19+
if(coin <= i)
20+
dp[i] = (dp[i] + dp[i-coin])%mod;
21+
}
22+
}
23+
cout << dp[x]%mod;
24+
25+
}
26+
27+
int main()
28+
{
29+
ios_base::sync_with_stdio(false);
30+
cin.tie(NULL);
31+
cout.tie(NULL);
32+
solve();
33+
}

coinCombination2.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "bits/stdc++.h"
2+
using namespace std;
3+
#define ll long long
4+
#define mod 1000000007
5+
6+
void solve()
7+
{
8+
ll n,x;
9+
cin >> n >> x;
10+
vector<ll> coins(n);
11+
for(ll i=0; i<n; i++) cin >> coins[i];
12+
13+
vector<ll> dp(x+1, 0);
14+
dp[0] = 1;
15+
16+
for(ll coin: coins)
17+
{
18+
for(ll i=1; i<=x; i++)
19+
{
20+
if(i >= coin)
21+
dp[i] = (dp[i] + dp[i-coin])%mod;
22+
}
23+
}
24+
cout << dp[x]%mod;
25+
}
26+
27+
int main()
28+
{
29+
ios_base::sync_with_stdio(false);
30+
cin.tie(NULL);
31+
cout.tie(NULL);
32+
solve();
33+
}

0 commit comments

Comments
 (0)