您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: