//aarifshuvo ``CSEJU #include <bits/stdc++.h> #define ll long long #define SZ(x) ((int)(x).size()) #define scl(x) scanf("%lld", &x) #define scll(x,y) scanf("%lld %lld", &x, &y) #define ALL(x) (x).begin(),(x).end() #define REP(i,n) for(int i=0;i<n;i++) #define REV(i,n) for(int i=n-1;i>=0;i--) #define FOR(i,a,b) for(int i=a;i<=b;i++) #define pri(a) cout<<a<<endl #define prii(a,b) cout<<a<<" "<<b<<endl using namespace std; ll dp[6][7500]; ll ar[] = {1,5,10,25,50}; ll ttl; ll calc(ll i, ll feas) { if(i==5) { if(feas==0) return 1; else return 0; } if(dp[i][feas]!=-1) return dp[i][feas]; dp[i][feas] = 0; for(int j=0; ; j++) { if(feas-ar[i]*j <0) break; dp[i][feas] += calc(i+1,feas - ar[i]*j); } return dp[i][feas]; } int main() { memset(dp,-1,sizeof dp); while(scl(ttl)==1) { printf("%lld\n",calc(0,ttl)); } return 0; }
~Be glad of life because it gives you the chance to love and to work and to play and to look at the stars.~
Thursday, June 1, 2017
UVa 674 Coin Change
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment