Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MuhammadJahidHasan/6c4227827f54a6a8c10cdeecef2d0041 to your computer and use it in GitHub Desktop.
Save MuhammadJahidHasan/6c4227827f54a6a8c10cdeecef2d0041 to your computer and use it in GitHub Desktop.
Coin Change Variant 1(DP)
#include <iostream>
using namespace std;
int main()
{
int coin[2]={2,4};
int n;
cin>>n;
int taka[n+1];
for(int i=0;i<=n;i++){
taka[i]=0;
}
taka[0]=1;
for(int j=0;j<2;j++){
for(int k=0;k<=n;k++){
if(k>=coin[j]){
taka[k]=taka[k]+taka[k-coin[j]];
}
}
}
for(int t=0;t<=n;t++){
cout<<taka[t]<<" ";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment