标签:des style http color java os io strong
/*
题目大意:
有1,2,5面值硬币,给定各自硬币数,求不能组成的最小面值总额
样例分析:1 1 3,能组成1,2,3,5,…,但组不成4
解题思路:母函数求解
难点详解:本题用到母函数,但是函数的括号数是知道的,所以直接用括号数就可以了。这样可以减少循环次数。还有就是代码上的注释部分
解题人:lingnichong
解题时间:2014-08-11 14:55:18
解体感受:母函数的另一种运用,是个典型的例子
*/
Holding Bin-Laden Captive!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14827 Accepted Submission(s): 6638
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!
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
Sample Output
#include<stdio.h>
#include<string.h>
#define MAXN 8000+10
int c1[MAXN],c2[MAXN];
int main()
{
int a,b,c,sum;
int i,j,k;
while(scanf("%d%d%d",&a,&b,&c),a||b||c)
{
memset(c1,0,sizeof(c1));
memset(c2,0,sizeof(c2));
for(i=0;i<=a;i++)
c1[i]=1;
for(i = 2, sum = a + 2 * b; i <= 5; i += 3, sum += 5*c)//i表示当前待选物体的‘价值’,sum 表示当前 选取的最大值
{
for(j = 0; j <= sum; j++)
for(k = 0; k+j <= sum; k += i)
c2[k+j]+=c1[j];
for(j = 0; j <= sum; j++)
{
c1[j]=c2[j];
c2[j]=0;
}
}
for(i = 1;i <= sum; i++)
if(!c1[i])
{
printf("%d\n",i);
break;
}
}
return 0;
}
HDU 1085 Holding Bin-Laden Captive!,布布扣,bubuko.com
HDU 1085 Holding Bin-Laden Captive!
标签:des style http color java os io strong
原文地址:http://blog.csdn.net/qq_16767427/article/details/38492603