Last active
March 29, 2018 15:35
-
-
Save MuhammadJahidHasan/6c4227827f54a6a8c10cdeecef2d0041 to your computer and use it in GitHub Desktop.
Coin Change Variant 1(DP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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