您的位置:首页 > 其它

【HDOJ 1085】数学问题,母函数

2015-07-26 14:06 267 查看

Holding Bin-Laden Captive!

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 17327 Accepted Submission(s): 7764


[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<iostream>
#include<algorithm>
using namespace std;
int main()
{
int a,b,c;
while( cin >> a >> b >> c,a,b,c)
{
if(a >= 4 || (a >= 2 && b >=1) || (a >= 1 && b >= 2))
{
cout << a + b * 2 + c * 5 + 1 << endl;
continue;
}
if(a == 0)
cout << "1" << endl;
else if(b == 0)
cout << a + 1 << endl;
else if(a == 1 && b == 1)
cout << "4" << endl;
}
return 0;
}


#include <iostream>
#include <memory.h>
#define N 8000
using namespace std;
int num[4];
int c1[N+10],c2[N+10];
int main()
{
int i,j,k;
int value[4]= {0,1,2,5};
while(cin>>num[1]>>num[2]>>num[3])
{
if(num[1]==0&&num[2]==0&&num[3]==0)
return 0;
int n=0;
for(i=1;i<=3;i++)
n+=num[i]*value[i];
memset(c1,0,sizeof(c1));
memset(c2,0,sizeof(c2));
c1[0]=1;
for (i=1; i<=3; i++)
{
for (j=0; j<=n; j++)
for (k=0; k*value[i]+j<=n&&k<=num[i]; k++)
{
c2[j+k*value[i]]+=c1[j];
}
for (j=0; j<=n; j++)
{
c1[j]=c2[j];
c2[j]=0;
}
}
int s;
for(s=1;s<=n;s++)
{
if(c1[s]==0)
break;
}
cout<<s<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: