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

Dynamic Programming: Coin Change Problem #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Coin_change_problem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//Deepak Rathore
//IIITDM kurnool
#include<bits/stdc++.h>
using namespace std;
int main()
{
int k,n;
cin>>k>>n;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
long long int dp[n][k+1];
for(int i=0;i<n;i++) {
dp[i][0]=1;
}
for(int i=0;i<=k;i++) {
if(i%arr[0]==0)
dp[0][i]=1;
}
for(int i=1;i<=n;i++) {
for(int j=1;j<=k;j++) {
if(j>=arr[i])
dp[i][j]=dp[i][j-arr[i]]+dp[i-1][j];
else
dp[i][j]=dp[i-1][j];
}
}
cout<<dp[n-1][k];
}