Problem Description
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.
Input
The input file contains any number of lines, each one consisting of a number ( ≤250 ) for the amount of money in cents.
Output
For each input line, output a line containing the number of different ways of making changes with the above 5 types of coins.
Sample Input
11
26
Sample Output
4
13
思路
二维母函数,由于硬币总数<=100,还需要开辟一个数组记录用的硬币数
/*************************************************************************
> File Name: hdu2069.cpp
> Author:gens_ukiy
> Mail:
> Created Time: 2016年11月30日 星期三 16时45分06秒
************************************************************************/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<map>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);(i++))
#define inf 0x3f3f3f
#define ll long long
#define maxn 255
int c1[maxn][105],c2[maxn][105],re[maxn];
int main()
{
int n;
int coin[5]={1,5,10,25,50};
memset(c1,0,sizeof(c1));
memset(c2,0,sizeof(c2));
c1[0][0]=1;
rep(i,0,4)
{
rep(j,0,250)
for(int k=0;k*coin[i]+j<=250;k++)
for(int p=0;k+p<=100;p++)
c2[j+k*coin[i]][p+k] += c1[j][p];
rep(j,0,250)
rep(p,0,100)
c1[j][p]=c2[j][p],c2[j][p]=0;
}
rep(i,1,250)
rep(j,0,100)
re[i] += c1[i][j];
re[0]=1;
while(cin>>n)
printf("%d\n",re[n]);
return 0;
}