- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####*******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define sc(n) scanf("%d", &n)
- #define S 30003
- using namespace std;
- typedef long long LL;
- LL N, dp[15][S];
- LL coins[] = {5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000};
- LL Dollars(int ind, LL tot){
- if(tot == 0LL)return 1LL;
- if(tot < 0)return 0LL;
- if(ind >= 11)return 0LL;
- if(dp[ind][tot] != -1LL)return dp[ind][tot];
- dp[ind][tot] = (Dollars(ind, tot-coins[ind])+Dollars(ind+1, tot));
- return dp[ind][tot];
- }
- void Do(){
- char n[10];
- memset(dp, -1LL, sizeof(dp));
- while(scanf("%s", n) == 1){
- N = 0LL;
- for(int i = 0; n[i]; i++){
- if(n[i] >= '0' && n[i] <= '9')
- N = (N*10LL)+(n[i]-'0');
- }
- if(N == 0LL)break;
- printf("%6s%17lld\n", n, Dollars(0, N));
- }
- }
- int main(){
- ios_base::sync_with_stdio(0); cin.tie(0);
- #ifndef ONLINE_JUDGE
- ///freopen("inp","r",stdout);
- ///freopen("contest.txt","w",stdout);
- #endif
- Do();
- return 0;
- }
Sunday, June 14, 2015
UVa - 147 - Dollars
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment