#include <iostream>
#include <vector>
using namespace std;
vector<int> coin={0,1,5,10,25,50};
vector<vector<long long int> > dp(6,vector<long long int>(30001,-1));
long long int cc(int i,long long int sum){
if(sum==0)return 1;
if(i==6)return 0;
if(dp[i][sum]!=-1)return dp[i][sum];
if(coin[i]>sum)return dp[i][sum]=0;
return dp[i][sum]=cc(i+1,sum)+cc(i,sum-coin[i]);
}
int main(){
int n;
while(cin>>n){
long long int ans=cc(1,n);
if(ans>1)cout<<"There are "<<ans<<" ways to produce "<<n<<" cents change."<<endl;
else cout<<"There is only 1 way to produce "<<n<<" cents change."<<endl;
}
return 0;
}
#include <vector>
using namespace std;
vector<int> coin={0,1,5,10,25,50};
vector<vector<long long int> > dp(6,vector<long long int>(30001,-1));
long long int cc(int i,long long int sum){
if(sum==0)return 1;
if(i==6)return 0;
if(dp[i][sum]!=-1)return dp[i][sum];
if(coin[i]>sum)return dp[i][sum]=0;
return dp[i][sum]=cc(i+1,sum)+cc(i,sum-coin[i]);
}
int main(){
int n;
while(cin>>n){
long long int ans=cc(1,n);
if(ans>1)cout<<"There are "<<ans<<" ways to produce "<<n<<" cents change."<<endl;
else cout<<"There is only 1 way to produce "<<n<<" cents change."<<endl;
}
return 0;
}
Comments
Post a Comment