#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
vector<int> coin={1,5,10,25,50};
vector<vector<long long int> > dp(5,vector<long long int> (7490,-1));
long long int cc(int i,int sum){
if(sum==0)return 1;
if(i==5)return 0;
if(coin[i]>sum)return 0;
if(dp[i][sum]!=-1)return dp[i][sum];
return dp[i][sum]=cc(i+1,sum)+cc(i,sum-coin[i]);
}
int main(){
int n;
while(cin>>n){
cout<<cc(0,n)<<endl;
}
return 0;
}
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
vector<int> coin={1,5,10,25,50};
vector<vector<long long int> > dp(5,vector<long long int> (7490,-1));
long long int cc(int i,int sum){
if(sum==0)return 1;
if(i==5)return 0;
if(coin[i]>sum)return 0;
if(dp[i][sum]!=-1)return dp[i][sum];
return dp[i][sum]=cc(i+1,sum)+cc(i,sum-coin[i]);
}
int main(){
int n;
while(cin>>n){
cout<<cc(0,n)<<endl;
}
return 0;
}
Comments
Post a Comment