Holding Bin-Laden Captive!(1.多重背包 2.母函数)
Holding Bin-Laden Captive! |
| Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) |
| Total Submission(s): 41 Accepted Submission(s): 29 |
|
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! |
|
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 |
|
Sample Output
4 |
|
Author
lcy
|
/*
题意:给你面值1,2,5的金币的个数,让你求出最小不能组成的金额 初步思路:暴力是不可取 1e12,以前做过一道丑数的题,这个题可以拿来参考一下 #错误:每个能凑成的数都是由前一个状态转移过来的
根本行不通,那个是没有数量限制的......多重背包再来搞一下,总共三种物品每个取或者不取,没有覆盖的点就是不能凑出来的 #感悟:......我去,竟然多重背包爆过了 */
#include<bits/stdc++.h>
using namespace std;
int num[];
int dp[];//dp[i]表示i是否能凑出来
int cur=;
int v[]={,,};
void init(){
memset(dp,,sizeof dp);
}
int main(){
//freopen("in.txt","r",stdin);
while(scanf("%d%d%d",&num[],&num[],&num[])!=EOF&&(num[]+num[]+num[])){
init();
cur=num[]+num[]*+num[]*;//总的钱数
dp[]=;
for(int i=;i<;i++){
for(int j=;j<num[i];j++){
for(int k=cur;k>=v[i];k--){
dp[k]+=dp[k-v[i]];
}
}
}
int id=cur+;
for(int i=;i<cur;i++){
//cout<<dp[i]<<" ";
if(!dp[i]){
id=i;
break;
}
}
printf("%d\n",id);
//cout<<endl;
}
return ;
}
未完......待续
Holding Bin-Laden Captive!(1.多重背包 2.母函数)的更多相关文章
- HDU 1059 Dividing 分配(多重背包,母函数)
题意: 两个人共同收藏了一些石头,现在要分道扬镳,得分资产了,石头具有不同的收藏价值,分别为1.2.3.4.5.6共6个价钱.问:是否能公平分配? 输入: 每行为一个测试例子,每行包括6个数字,分别对 ...
- 洛谷P1782 旅行商的背包[多重背包]
题目描述 小S坚信任何问题都可以在多项式时间内解决,于是他准备亲自去当一回旅行商.在出发之前,他购进了一些物品.这些物品共有n种,第i种体积为Vi,价值为Wi,共有Di件.他的背包体积是C.怎样装才能 ...
- HDU 2082 找单词 (多重背包)
题意:假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于给定的字母,可以找到多少价值<=50的 ...
- Poj 1276 Cash Machine 多重背包
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26172 Accepted: 9238 Des ...
- poj 1276 Cash Machine(多重背包)
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33444 Accepted: 12106 De ...
- (混合背包 多重背包+完全背包)The Fewest Coins (poj 3260)
http://poj.org/problem?id=3260 Description Farmer John has gone to town to buy some farm supplies. ...
- (多重背包+记录路径)Charlie's Change (poj 1787)
http://poj.org/problem?id=1787 描述 Charlie is a driver of Advanced Cargo Movement, Ltd. Charlie dri ...
- 单调队列优化DP,多重背包
单调队列优化DP:http://www.cnblogs.com/ka200812/archive/2012/07/11/2585950.html 单调队列优化多重背包:http://blog.csdn ...
- POJ1742 Coins[多重背包可行性]
Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 34814 Accepted: 11828 Descripti ...
随机推荐
- GCD之死锁体会
1.先看下几句代码 1 2 3 4 5 6 7 dispatch_queue_t serialqueue=dispatch_queue_create("serialqueue", ...
- Redis学习——Redis事务
Redis和传统的关系型数据库一样,因为具有持久化的功能,所以也有事务的功能! 有关事务相关的概念和介绍,这里就不做介绍. 在学习Redis的事务之前,首先抛出一个面试的问题. 面试官:请问Redis ...
- Spring Boot Document Part II(上)
Part II. Getting started 这一章内容适合刚接触Spring Boot或者"Spring"家族的初学者!随着安装指导说明,你会发现对Spring boot有一 ...
- HDU2282 Chocolate KM算法
第一次做这样的题,其中有几个细节是反复思考反复调试,最后一A的,ORZ,又加深了对KM算法的理解.能不参考网上的题解,而是平静下来思考,参透,最后敢于尝试.....真的很重要,以后遇到才会有更深的印象 ...
- DevOps之服务器
唠叨话 关于德语噢屁事的知识点,仅提供专业性的精华汇总,具体知识点细节,参考教程网址,如需帮助,请留言. <服务器(Server)> DevOps之服务器划分为三部分:系统.虚拟化.器件. ...
- IIS ApplicationPoolIdentity(配置IIS讀寫網站文件)
原创地址:http://www.cnblogs.com/jfzhu/p/4067297.html 转载请注明出处 从IIS 7.5开始,Application Pool Identity的Built- ...
- string使用
一.list和string转化 List转字符串,用逗号隔开 List<string> list = new List<string>();list.Add("a&q ...
- win10 uwp 简单MasterDetail
中文 English 本文主要讲实现一个简单的界面,可以在窗口比较大显示列表和内容,窗口比较小时候显示列表或内容.也就是在窗口比较小的时候,点击列表会显示内容,点击返回会显示列表. 先放图,很简单. ...
- win10 uwp App-to-app communication 应用通信
这篇文章都是乱说的,如果觉得有不好的,可以发我邮箱 应用之间需要相互的发送信息,就是我们经常用的分享 有个人看到一个网页很好,于是就希望把这个网页发送到邮件,那么这样的话就是使用应用通信. 因为每个应 ...
- putty 的美化
1. 中文乱码问题. 这个问题由来已久,每当我查看 mount到linux下的windows 中文目录的时候,都是一堆乱码, putty 也拒绝我输入中文, 一句话,这玩意,对中文过敏. ...
