hdu1085 母函数的应用之每种硬币有个数限制
来源:互联网 发布:大智慧编程教程 编辑:程序博客网 时间:2024/05/01 22:04
Holding Bin-Laden Captive!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8814 Accepted Submission(s): 3963
Problem Description
We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China!
“Oh, God! How terrible! ”
Don’t be so afraid, guys. Although he hides in a cave of Hang Zhou, he dares not to go out. Laden is so bored recent years that he fling himself into some math problems, and he said that if anyone can solve his problem, he will give himself up!
Ha-ha! Obviously, Laden is too proud of his intelligence! But, what is his problem?
“Given some Chinese Coins (硬币) (three kinds-- 1, 2, 5), and their number is num_1, num_2 and num_5 respectively, please output the minimum value that you cannot pay with given coins.”
You, super ACMer, should solve the problem easily, and don’t forget to take $25000000 from Bush!
“Oh, God! How terrible! ”
Don’t be so afraid, guys. Although he hides in a cave of Hang Zhou, he dares not to go out. Laden is so bored recent years that he fling himself into some math problems, and he said that if anyone can solve his problem, he will give himself up!
Ha-ha! Obviously, Laden is too proud of his intelligence! But, what is his problem?
“Given some Chinese Coins (硬币) (three kinds-- 1, 2, 5), and their number is num_1, num_2 and num_5 respectively, please output the minimum value that you cannot pay with given coins.”
You, super ACMer, should solve the problem easily, and don’t forget to take $25000000 from Bush!
Input
Input contains multiple test cases. Each test case contains 3 positive integers num_1, num_2 and num_5 (0<=num_i<=1000). A test case containing 0 0 0 terminates the input and this test case is not to be processed.
Output
Output the minimum positive value that one cannot pay with given coins, one line for one case.
Sample Input
1 1 30 0 0
Sample Output
4题意:用1 2 5的硬币买不到的东西的价值(输出最小的)3者数量分别为num1 num2 num3
#include "stdio.h"int c1[10000],c2[10000];int main(){ int i,j,k,num1,num2,num3,n; while(scanf("%d %d %d",&num1,&num2,&num3)!=EOF) { if(!num1&&!num2&&!num3) break; n=num3*5+num2*2+num1; for(i=0;i<=n;i++) { c1[i]=0; c2[i]=0; } for (i=0;i<=num1;i++) c1[i]=1; for(j=0;j<=num1;j++) // for (k=0;k+j<=num2*2;k=k+2)//num2*2表示最多可能达到的次数 for (k=0;k<=num2*2;k=k+2)//num2*2表示最多可能达到的次数 { //注意 这里不要用k+j<=num2 因为以前求整数拆分输入数n 要保证次数小于n 因为最大为 //x的n次方 表示为1个重为n的砝码 这里是求多项式相乘 不用限制了 c2[j+k]+=c1[j]; } for (j=0;j<=num2*2+num1;j++)//因为 下面的c2[j] 中的下标最大为j+k 由上一步可以看出 而j最大为num1 k最大为num2*2 { c1[j]=c2[j]; c2[j]=0; } for(j=0;j<=num2*2+num1;j++)//num1和num2*2不一定那个大那 要表示出所有的项数 所以要这样 for(k=0;k<=num3*5;k+=5) c2[j+k]+=c1[j]; for (j=0;j<=num3*5+num2*2+num1;j++) { c1[j]=c2[j]; c2[j]=0; } for (i=0;i<=n;i++) if(!c1[i]) {printf("%d\n",i);break;} if(i==n+1) printf("%d\n",i); }}
- hdu1085 母函数的应用之每种硬币有个数限制
- hdu1284 母函数之每种硬币都是无限的
- hdu2069 母函数应用变形之总硬币数有限制
- hdu2802 母函数每种有限制 经典 很深刻
- hdu1085(三种硬币组成的数字母函数
- poj 1787 求达到总钱数的选硬币的最大数量(硬币有个数限制)
- hdu1085(母函数解有限个硬币组合问题)
- hdu1085 母函数的运用
- 计算最少用到的硬币个数以用每种面值的用数
- hdu1085 母函数
- hdu1085(母函数)
- HDU1085(母函数)
- HDU1085(母函数)
- hdu1085【母函数入门】
- HDU1085(母函数模板)
- hdu1085母函数模板
- hdu1085(母函数/完全背包)
- 【拉灯君第三弹】母函数-HDU1085-泰山下的AC
- 图像处理之仿画笔效果一
- POJ 1007(求逆序对数)
- 程序员如何提高自己的英语水平?
- jquery xheditor
- Twitter粉丝交易猖獗:1000个粉丝18美元
- hdu1085 母函数的应用之每种硬币有个数限制
- web2.0网站十二行打油诗
- hibernate映射继承关系三
- android ntfs-3g移植
- Repeater中的下拉列表DropDownList绑定数据源
- 电商将迎“史上最惨烈”价格战
- 二叉排序树的实现
- hdu1284 母函数之每种硬币都是无限的
- jQuery.validate.js插件使用(struts2的整合)