HDU 1085 Holding Bin-Laden Captive! [母函数]
2018-03-12 19:21
543 查看
Holding Bin-Laden Captive!
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 30 Accepted Submission(s) : 15[align=left]Problem Description[/align]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!
[align=left]Input[/align]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.
[align=left]Output[/align]Output the minimum positive value that one cannot pay with given coins, one line for one case.
[align=left]Sample Input[/align]1 1 3
0 0 0
[align=left]Sample Output[/align]4
[align=left]Author[/align]lcy
#include <stdio.h> #include <string.h> int main(int argc, char *argv[]) { int a[5]; int c1[100500],c2[100500]; int n1,n2,n3; int i,j,k,kk; int sum; while(scanf("%d %d %d",&a[1],&a[2],&a[5])!=EOF&&(a[1]||a[2]||a[5])) { sum=a[1]*1+a[2]*2+a[5]*5;//代表一共有多少个 memset(c1,0,sizeof(c1)); memset(c2,0,sizeof(c2)); for(i=0;i<=a[1];i++) c1[i]=1;//第一括号里的系数都标为1 for(i=2;i<=5;i+=3) { for(j=0;j<=sum;j++) for(k=0;k+j<=sum&&k/i<=a[i];k+=i) c2[k+j]+=c1[j]; for(j=0;j<=sum;j++) { c1[j]=c2[j]; c2[j]=0; } } for(j=1;j<=sum;j++) if(!c1[j]) break; printf("%d\n",j); } return 0; }
相关文章推荐
- HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)
- hdu 1085 Holding Bin-Laden Captive!(母函数)
- HDU 1085 Holding Bin-Laden Captive! 母函数③
- hdu1085 Holding Bin-Laden Captive!(母函数)
- HDU 1085 Holding Bin-Laden Captive!(母函数)
- hdu 1085 Holding Bin-Laden Captive! (母函数)
- HDU——1085 Holding Bin-Laden Captive!(母函数)
- 【HDU 1085】【母函数】Holding Bin-Laden Captive!【给你a1个一元硬币,a2个两元硬币,a3个五元硬币,问不能凑出来的第一个面额是多少】
- HDU 1085 Holding Bin-Laden Captive!(母函数)
- HDU 1085 Holding Bin-Laden Captive!(母函数)
- HDU 1085 Holding Bin-Laden Captive! (本来想用母函数的,结果直接爆了)
- hdu 1085 Holding Bin-Laden Captive!(母函数)
- HDU 1085 Holding Bin-Laden Captive!(母函数)
- HDU 1085-Holding Bin-Laden Captive!(母函数)
- [母函数]HDU 1085——Holding Bin-Laden Captive!
- HDU_1085_Holding Bin-Laden Captive!_母函数
- hdu 1085 Holding Bin-Laden Captive! 母函数的基本运用,,还是不难的
- HDU 1085 Holding Bin-Laden Captive! 母函数||背包||递推
- hdu 1085 Holding Bin-Laden Captive!(母函数/背包)
- hdu 1085 Holding Bin-Laden Captive! (母函数)