Holding Bin-Laden Captive!(hdoj1085)代码并未完全看懂
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! ”
![](http://acm.hdu.edu.cn/data/images/1085_1.jpg)
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! ”
![](http://acm.hdu.edu.cn/data/images/1085_1.jpg)
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 3
0 0 0
Sample Output
4
1 #include<stdio.h> 2 #include<string.h> 3 #include<math.h> 4 5 int n1[8005],n2[8005]; 6 int num[4],p[4],sum; 7 8 void fuction() 9 { 10 memset(n1,0,sizeof(n1)); 11 memset(n2,0,sizeof(n2)); 12 n1[0]=1;/*注意,0面值也要算在内,不然后面if(n1[j])不通过,因为假如要计算1面币是否存在,1=1+0,所以0面币要存在*/ 13 int i,j,k; 14 for(i=1;i<=3;i++)//1 2 5硬币 15 { 16 for(j=0;j<=sum;j++)//产生的面额 17 for(k=0;k<=num[i]&&k*p[i]+j<=sum;k++)//个数,判断是否超出sum 18 if(n1[j]) 19 n2[k*p[i]+j]=1;/*没有明白为什么要赋值1,怎么不是他的个数??*/ 20 for(j=0;j<=sum;j++) 21 { 22 n1[j]=n2[j]; 23 n2[j]=0; 24 } 25 } 26 } 27 int main() 28 { 29 p[1]=1,p[2]=2,p[3]=5; 30 int i; 31 while(~scanf("%d%d%d",&num[1],&num[2],&num[3])&&(num[1]||num[2]||num[3])) 32 { 33 sum=p[1]*num[1]+p[2]*num[2]+p[3]*num[3]; 34 fuction(); 35 for(i=0;i<=sum+1;i++) 36 if(n1[i]==0) 37 { 38 printf("%d\n",i); 39 break; 40 } 41 } 42 return 0; 43 }