您的位置:首页 > 其它

HDU 1085 Holding Bin-Laden Captive!(母函数)

2016-02-14 18:47 746 查看
题目:HDU-1085

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1085

题目:


Holding Bin-Laden Captive!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 19057    Accepted Submission(s): 8478


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

1 1 3
0 0 0

 

Sample Output

4

 

额,这道题目呢,意思是给三个硬币的数量,问不能组成的最小金额是多少,这道题目用来体会不同步骤代表什么意思挺好的,不怕写错,就怕不错哦~注释见

#include<iostream>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<cstdio>
using namespace std;
const int maxn= 10005;
int a[maxn],b[maxn];
int dir[3]={1,2,5},num[3];
int main(){
while(cin>>num[0]>>num[1]>>num[2]){
if(num[0]==0 && num[1]==0 && num[2]==0) break;
for(int i=0;i<=num[0]+num[1]*2+num[2]*5;i++){
a[i]=0;
b[i]=0;
}
int t=0;
for(int i=0;i<=num[0];i++) a[i]=1;
for(int i=1;i<3;i++){
t+=num[i-1]*dir[i-1];
for(int j=0;j<=t;j++)            //可以思考一下这里为什么需要用一个t来存,每次循环t怎么变化,代表什么意思
for(int k=0;k<=num[i]*dir[i];k+=dir[i]){
b[j+k]+=a[j];
}
for(int j=0;j<=t+num[i]*dir[i];j++){
a[j]=b[j];
b[j]=0;
}
}
int k=0;
for(int i=0;i<=num[0]+num[1]*2+num[2]*5;i++)
if(a[i]==0){
k=1;
cout<<i<<endl;
break;
}
if(k==0)
cout<<num[0]+num[1]*2+num[2]*5+1<<endl;

}
return 0;
}

好好学习,加油~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: