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!

 

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
 
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[],m2[];
int n1,n2,n3,s,Max,tmp,L,i,j;
void _work()
{
tmp=;
while(n1>) {
if(n1>=tmp) m2[++L]=*tmp;
else m2[++L]=*n1;
n1-=tmp;
tmp*=;
}
tmp=;
while(n2>) {
if(n2>=tmp) m2[++L]=*tmp;
else m2[++L]=*n2;
n2-=tmp;
tmp*=;
}
tmp=;
while(n3>) {
if(n3>=tmp) m2[++L]=*tmp;
else m2[++L]=*n3;
n3-=tmp;
tmp*=;
}
}
int main()
{
while(~scanf("%d%d%d",&n1,&n2,&n3)){
if(n1==&&n2==&&n3==) return ;
L=;
Max=n1+n2*+n3*;
memset(m,,sizeof(m));
m[]=; _work();
for(i=;i<=L;i++)
for(j=Max;j>=;j--)
if(j-m2[i]>=&&m[j-m2[i]]==) m[j]=;
for(i=;i<=Max;i++)
if(!m[i]) break;
cout<<i<<endl;
}
return ;
}

 

HDU1085 多重背包的更多相关文章

  1. 洛谷P1782 旅行商的背包[多重背包]

    题目描述 小S坚信任何问题都可以在多项式时间内解决,于是他准备亲自去当一回旅行商.在出发之前,他购进了一些物品.这些物品共有n种,第i种体积为Vi,价值为Wi,共有Di件.他的背包体积是C.怎样装才能 ...

  2. HDU 2082 找单词 (多重背包)

    题意:假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于给定的字母,可以找到多少价值<=50的 ...

  3. Poj 1276 Cash Machine 多重背包

    Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26172   Accepted: 9238 Des ...

  4. poj 1276 Cash Machine(多重背包)

    Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33444   Accepted: 12106 De ...

  5. (混合背包 多重背包+完全背包)The Fewest Coins (poj 3260)

    http://poj.org/problem?id=3260   Description Farmer John has gone to town to buy some farm supplies. ...

  6. (多重背包+记录路径)Charlie's Change (poj 1787)

    http://poj.org/problem?id=1787   描述 Charlie is a driver of Advanced Cargo Movement, Ltd. Charlie dri ...

  7. 单调队列优化DP,多重背包

    单调队列优化DP:http://www.cnblogs.com/ka200812/archive/2012/07/11/2585950.html 单调队列优化多重背包:http://blog.csdn ...

  8. POJ1742 Coins[多重背包可行性]

    Coins Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 34814   Accepted: 11828 Descripti ...

  9. POJ1276Cash Machine[多重背包可行性]

    Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 32971   Accepted: 11950 De ...

随机推荐

  1. 开始学习.net的第二天

    今天由于原因上午没上课.下午去了学的.net的表格. <body></body><img src="../temp/新建文件夹/64aab4ae3e632dbc ...

  2. RobotFramework安装完成后怎么在桌面显示ride图标

    安装了RobotFramework后,怎么让桌面上显示带有机器人的图标呢? 一.桌面上创建ride快捷方式 进入到python的安装目录的/Scripts目录下,找到ride.py文件-->右键 ...

  3. 201521123027 《JAVA程序设计》第3周学习总结

    1.本周学习总结 2.书面作业 Q1.代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; pu ...

  4. 201521123114 《Java程序设计》第2周学习总结

    #1. 本周学习总结 1. 学会了使用码云管理代码,使用eclipse关联jdk源代码: 2. 学习了包管理机制,包的作用:主要是管理java文件,解决同名文件冲突; 3. ArrayList可以处理 ...

  5. 笔记2 linux多线程 读写锁

    //read write lock #include<stdio.h> #include<unistd.h> #include<pthread.h> struct ...

  6. 基于socket.io的实时在线选座系统

    基于socket.io的实时在线选座系统(demo) 前言 前段时间公司做一个关于剧院的项目,遇到了这样一种情况. 在高并发多用户同时选座的情况下,假设A用户进入选座页面,正在选择座位,此时还没有提交 ...

  7. JSP获取Cookie对象

    cookie是小段的文本信息,在网络服务器上生成,并发送给浏览器的.通过使用cookie可以标识用户身份,记录用户和密码,跟踪重复用户等.浏览器将cookie以key/value的形式保存到客户机的某 ...

  8. Apache Spark 2.2.0 中文文档 - Spark Streaming 编程指南 | ApacheCN

    Spark Streaming 编程指南 概述 一个入门示例 基础概念 依赖 初始化 StreamingContext Discretized Streams (DStreams)(离散化流) Inp ...

  9. CSS3微信启动页天王星版

    今天被微信启动页刷屏了. 一直还以为启动页背景显示的月球的.今天才了解到这么有含义. 我也蹭一下微信的热度,做一个HTML+CSS版本的. 用CSS画地球太困难了,来个简单点的,天王星版. 主要使用到 ...

  10. 详解 HTTPS 移动端对称加密套件优

    近几年,Google.Baidu.Facebook 等互联网巨头大力推行 HTTPS,国内外的大型互联网公司很多也都已启用全站 HTTPS. Google 也推出了针对移动端优化的新型加密套件 Cha ...