Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimum subsetsum difference (Dynamic Progrmming) #393

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Create maximum coin change problem(DP)
ManishBadsara authored Oct 27, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 22b74fb7bb2491162aec35f2debd18c7294a3ed5
44 changes: 44 additions & 0 deletions Programs/maximum coin change problem(DP)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//maximum coin change problem ->DP (Dynamic Programming).

#include<bits/stdc++.h>
using namespace std;
#define ll long long

void maxcoins(vector<ll>v,ll k)
{
ll n=v.size();
ll dp[n+1][k+1];
for(ll i=0;i<=n;++i) dp[i][0]=1;
for(ll i=1;i<=k;++i) dp[0][i]=0;
for(ll i=1;i<=n;++i)
{
for(ll j=1;j<=k;++j)
{
if(v[i-1]<=j)
dp[i][j]=dp[i][j-v[i-1]]+dp[i-1][j]; // making an optimal choice..
else
dp[i][j]=dp[i-1][j]; // rejection..
}
}
cout<<"So the Maximal possible ways are:"<<endl;
cout<<dp[n][k]<<endl;
}
int main()
{
ll n,k;
cout<<"Enter the Amount: ";
cin>>k;
cout<<"\n";
cout<<"Enter the total no of coins for change : ";
cin>>n;
cout<<endl;
vector<ll>a;
ll c;
for(ll i=0;i<n;++i)
{
cin>>c;
a.push_back(c);
}
maxcoins(a,k);
//happy coding....
}