// 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 n, mem[6][31000]; ll coins[] = {1, 5, 10, 25, 50}; ll call(ll i, ll feas) { if(feas==0) return 1; if(i==5) return 0; if(mem[i][feas]!=-1) return mem[i][feas]; mem[i][feas] = 0; for(int j=0; feas-coins[i]*j>=0; j++) { mem[i][feas] += call(i+1, feas-coins[i]*j); } return mem[i][feas]; } int main() { memset(mem,-1,sizeof mem); while(~scl(n)) { ll res = call(0,n); if(res==1) printf("There is only 1 way to produce %lld cents change.\n", n); else printf("There are %lld ways to produce %lld cents change.\n", res, n); } 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 357 Let Me Count The Ways
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment