Coin Change
Time Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7813Accepted Submission(s): 2592
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
Sample Output
题意: 有50 25 10 5 1 的硬币 一共最多有100枚输入n输出有多少种表示方法
#include<stdio.h>
#include<string.h>
int c1[251][101],c2[251][101];//次数顶多为250 前一个括号是指系数 后一个指硬币个数
int main()
{
int i,j,k,n,l,sum;
int val[6]={0,1,5,10,25,50};
memset(c1,0,sizeof(c1));
memset(c2,0,sizeof(c2));
for(i=0;i<=100;i++)
{
c1[i][i]=1;
}
n=250;
for(i=2;i<=5;i++)
{
for(j=0;j<=n;j++)
for(k=0;k+j<=n;k+=val[i])//次方最大为k+j所以要控制它小于n
for(l=0;l+k/val[i]<=100;l++)
c2[k+j][l+k/val[i]]+=c1[j][l];
for(k=0;k<=n;k++)
for(l=0;l<=100;l++)
{
c1[k][l]=c2[k][l];
c2[k][l]=0;
}
}
while(scanf("%d",&n)!=EOF)
{
sum=0;
for(i=0;i<=100;i++)
sum+=c1[n][i];
printf("%d\n",sum);
}
// }
return 0;
}
此题给了一个思路 就是如何去求一个n拆分成各种硬币 一共用了多少个硬币
分享到:
相关推荐
(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数
90%的杭电母函数解题报告,有题目加解题思路,和ac掉的代码
ACM培训好资料!能帮助你快速提高ACM AC题目的能力,值得一下
acm 技术大牛 课件 HDU ...(lecture_06)母函数 (lecture_7)特殊的数 (lecture_8)组合博弈入门 (lecture_09贪心算法 (lecture_11)搜索入门 (lecture_12)二分匹配及其应用 (lecture_13)动态规划(2) 并查集
hdu 1695 GCD(欧拉函数+容斥原理).docx
杭电ACM课件2014版之(HDUACM2010版_13)二分匹配及其应用
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
杭电ACMhdu1163
hdu1001解题报告
HDU1059的代码
hdu 1574 passed sorce
HDU的一题........HDU DP动态规
ACM hdu 代码大全3000例,hdu已经AC的3000例代码,部分代码有详细解析
HDU二分匹配及其应用,此PPT是刘春英老师版权所有, 特此贡献给广大编程爱好者,特别是对于ACMer
hdu2101AC代码
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
搜索 dfs 解题代码 hdu1241
hdu 5007 Post Robot 字符串枚举。 暴力一下就可以了。