HDU1085 多重背包
来源:互联网 发布:张杰 他不懂 知乎 编辑:程序博客网 时间:2024/05/16 15:42
Holding Bin-Laden Captive!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 23275 Accepted Submission(s): 10358
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!
“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 30 0 0
Sample Output
4
Author
lcy
#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<string>#include<memory.h>#include<algorithm>#include<map>#include<queue>using namespace std;int m[8010],m2[30];int n1,n2,n3,s,Max,tmp,L,i,j;void _work(){tmp=1;while(n1>0) {if(n1>=tmp) m2[++L]=1*tmp;else m2[++L]=1*n1;n1-=tmp;tmp*=2; } tmp=1;while(n2>0) {if(n2>=tmp) m2[++L]=2*tmp;else m2[++L]=2*n2;n2-=tmp;tmp*=2; } tmp=1;while(n3>0) {if(n3>=tmp) m2[++L]=5*tmp;else m2[++L]=5*n3;n3-=tmp;tmp*=2; }}int main(){while(~scanf("%d%d%d",&n1,&n2,&n3)){if(n1==0&&n2==0&&n3==0) return 0;L=0;Max=n1+n2*2+n3*5;memset(m,0,sizeof(m));m[0]=1; _work();for(i=1;i<=L;i++) for(j=Max;j>=1;j--) if(j-m2[i]>=0&&m[j-m2[i]]==1) m[j]=1; for(i=0;i<=Max;i++) if(!m[i]) break; cout<<i<<endl;}return 0;}
阅读全文
0 0
- HDU1085 多重背包
- hdu1085 Holding Bin-Laden Captive! (多重背包)
- hdu1085(母函数/完全背包)
- hdu1085
- hdu1085
- hdu1085
- 多重背包
- 多重背包
- 多重背包
- 多重背包
- 多重背包
- 多重背包
- 多重背包
- 多重背包
- 多重背包
- 多重背包
- 【多重背包】
- 多重背包
- UVA
- SDUT 2056 不敢死队问题(循环表)
- 恒大vs上港,奇迹险些出现!
- ubuntu Anaconda change mode
- AngularJS路由、过滤。
- HDU1085 多重背包
- 管理员
- Docker小技巧(一)——阿里云CentOS7加速
- ZED stereo安装及使用相关
- 用户表单
- Unity 中XML序列化和反序列化
- SpringBoot学习之整合SSM+pagehelper+druid+单元测试
- (二)静态链表
- 十一个行为型模式5:中介者模式-Mediator Pattern【学习难度:★★★☆☆,使用频率:★★☆☆☆】