Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money.
For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent coin, or two 5-cent coins and one 1-cent coin, or one 5-cent coin and six 1-cent coins, or eleven 1-cent coins. So there are four ways of making changes for 11 cents with the above coins. Note that we count that there is one way of making change for zero cent.
Write a program to find the total number of different ways of making changes for any amount of money in cents. Your program should be able to handle up to 100 coins.
n ≤ 250 n ≤ 250 n≤250
input
11
26
76
145
239
output
4
13
134
828
3140
code
//Siberian Squirrel
//#include<bits/stdc++.h>
#include<unordered_map>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#define ACM_LOCAL
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const double eps = 1e-7;
const int inf = 0x3f3f3f3f;
const int MOD = 3221225473;
const int N = 8e3 + 10;
const int UP = 101;
int p[6] = {1, 50, 25, 10, 5, 1};
int f1[N][UP], f2[N][UP];
inline ll solve(int n, ll res = 0) {
memset(f1, 0, sizeof(f1));
f1[0][0] = 1;
for(int i = 1; i <= 5; ++ i) {
for(int j = 0; j <= n; ++ j) {
for(int k = 0; j + k * p[i] <= n && k <= 100; ++ k) {
for(int l = 0; l <= 100 && l + k <= 100; ++ l) {
f2[j + k * p[i]][l + k] += f1[j][l];
}
}
}
for(int j = 0; j <= n; ++ j) {
for(int k = 0; k <= 100; ++ k) {
f1[j][k] = f2[j][k];
f2[j][k] = 0;
}
}
}
for(int i = 1; i <= 100; ++ i) res += f1[n][i];
return n? res: 1;
}
int main() {
#ifdef ACM_LOCAL
// freopen("input", "r", stdin);
freopen("output", "w", stdout);
#endif
int o = 1, n, m, v;
// scanf("%d", &o);
while(o --) {
while(~scanf("%d", &n)) {
printf("%lld\n", solve(n));
}
}
return 0;
}