http://acm.hdu.edu.cn/showproblem.php?pid=2069
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.
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,dp[110][300]; // dp[j][k] 統計到第i個coins k錢 dived to j 部分 的分法數
int money[5]={1,5,10,25,50};
int main(){
//freopen("input.txt","r",stdin);
while(~scanf("%d",&n)){
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(int i=0;i<5;i++)
for(int j=1;j<=100;j++)
for(int k=n;k>=money[i];k--) //這樣寫應該使對的,可寫成這樣for(int k=money[i];k<=n;k++) 也沒WA,估計數據弱了
dp[j][k]+=dp[j-1][k-money[i]];
int ans=0;
for(int i=0;i<=100;i++) //從0開始,注意 dp[0][0]
ans+=dp[i][n];
printf("%d\n",ans);
}
return 0;
}
#include<stdio.h>
int main()
{
int a,b,c,d,e,count,n;
while(scanf("%d",&n)!=EOF)
{
count=0;
for(a=0;a<=100;a++)
for(b=0;5*b<=n;b++)
for(c=0;10*c<=n;c++)
for(d=0;25*d<=n;d++)
for(e=0;50*e<=n;e++)
if(a+5*b+10*c+25*d+50*e==n&&a+b+c+d+e<=100)count++;
printf("%d\n",count);
}
}
#include<stdio.h>
int main()
{
int a[]={1,1,1,1,1,2,2,2,2,2,4,4,4,4,4,6,6,6,6,6,9,9,
9,9,9,13,13,13,13,13,18,18,18,18,18,24,24,24,24,24,31,
31,31,31,31,39,39,39,39,39,50,50,50,50,50,62,62,62,62,62,
77,77,77,77,77,93,93,93,93,93,112,112,112,112,112,134,134,
134,134,134,159,159,159,159,159,187,187,187,187,187,218,218,
218,218,218,252,252,252,252,252,292,291,291,291,291,333,333,
333,333,332,380,380,380,379,378,430,430,429,428,427,485,484,
483,482,482,544,543,542,541,539,608,607,606,604,602,677,676,
673,671,670,751,748,746,744,743,828,825,823,822,818,912,910,
908,904,900,1001,999,995,990,986,1098,1093,1088,1084,1081,1196,
1191,1186,1182,1177,1301,1296,1292,1285,1278,1413,1408,1400,
1393,1387,1532,1524,1515,1508,1503,1654,1644,1637,1631,1622,1782,
1773,1766,1757,1746,1916,1909,1898,1886,1875,2061,2049,2037,2025,
2015,2208,2194,2181,2170,2156,2361,2348,2336,2321,2306,2521,2508,
2492,2475,2459,2691,2673,2654,2637,2622,2863,2843,2824,2808,2789,
3042,3021,3004,2983,2960,3228,3209,3187,3164,3140,3424,3401,3376,
3351,3329,3623,3596,3570,3545,3517,3830,},n;
while(scanf("%d",&n)!=EOF)
printf("%d\n",a[n]);
}