poj 1384 Piggy-Bank(完全背包)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 10830 | Accepted: 5275 |
Description
But there is a big problem with piggy-banks. It is not possible to determine how much money is inside. So we might break the pig into pieces only to find out that there is not enough money. Clearly, we want to avoid this unpleasant situation. The only possibility is to weigh the piggy-bank and try to guess how many coins are inside. Assume that we are able to determine the weight of the pig exactly and that we know the weights of all coins of a given currency. Then there is some minimum amount of money in the piggy-bank that we can guarantee. Your task is to find out this worst case and determine the minimum amount of cash inside the piggy-bank. We need your help. No more prematurely broken pigs!
Input
Output
Sample Input
3
10 110
2
1 1
30 50
10 110
2
1 1
50 30
1 6
2
10 3
20 4
Sample Output
The minimum amount of money in the piggy-bank is 60.
The minimum amount of money in the piggy-bank is 100.
This is impossible.
Source
//176K 94MS C++ 650B
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
#define M -0x7fffffff
int dp[];
int p[],w[];
int main(void)
{
int cas,e,f,n;
scanf("%d",&cas);
while(cas--){
scanf("%d%d",&e,&f);
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d%d",&p[i],&w[i]);
} for(int i=;i<=f;i++){
dp[i] = M;
}
dp[] = ;
for(int i=;i<n;i++){
for(int j=w[i];j<=f-e;j++){
if(dp[j-w[i]] != M)
dp[j] = max(dp[j], dp[j-w[i]] - p[i]);
}
}
if(dp[f-e]==M){
puts("This is impossible.");
}else{
printf("The minimum amount of money in the piggy-bank is %d.\n", -dp[f-e]);
}
}
return ;
}
poj 1384 Piggy-Bank(完全背包)的更多相关文章
- poj 1384 Piggy-Bank(全然背包)
http://poj.org/problem?id=1384 Piggy-Bank Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- POJ 1384 Piggy-Bank (完全背包)
Piggy-Bank 题目链接: http://acm.hust.edu.cn/vjudge/contest/130510#problem/F Description Before ACM can d ...
- POJ 1384 Piggy-Bank【完全背包】+【恰好完全装满】(可达性DP)
题目链接:https://vjudge.net/contest/217847#problem/A 题目大意: 现在有n种硬币,每种硬币有特定的重量cost[i] 克和它对应的价值val[i]. 每 ...
- POJ 1745 【0/1 背包】
题目链接:http://poj.org/problem?id=1745 Divisibility Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
- POJ 3181 Dollar Dayz(全然背包+简单高精度加法)
POJ 3181 Dollar Dayz(全然背包+简单高精度加法) id=3181">http://poj.org/problem?id=3181 题意: 给你K种硬币,每种硬币各自 ...
- POJ 3211 Washing Clothes(01背包)
POJ 3211 Washing Clothes(01背包) http://poj.org/problem?id=3211 题意: 有m (1~10)种不同颜色的衣服总共n (1~100)件.Dear ...
- POJ 1384 POJ 1384 Piggy-Bank(全然背包)
链接:http://poj.org/problem?id=1384 Piggy-Bank Time Limit: 1000MS Memory Limit: 10000K Total Submissio ...
- POJ 1384 Piggy-Bank (ZOJ 2014 Piggy-Bank) 完全背包
POJ :http://poj.org/problem?id=1384 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode ...
- POJ 1384 Piggy-Bank 背包DP
所谓的全然背包,就是说物品没有限制数量的. 怎么起个这么intimidating(吓人)的名字? 事实上和一般01背包没多少差别,只是数量能够无穷大,那么就能够利用一个物品累加到总容量结尾就能够了. ...
随机推荐
- 2.1 ARM家族大检阅
芯片名称 ARM核 指令架构 S3C2440 ARM9 ARMv4T S3C6410 ARM11 ARMv6 S5PV210 Cortex A8 ARMv7-A Cortex M工控 Cortex R ...
- OGC学习课程
1.引言 由于项目需要,需要学习OGC相关地图标准,包括WMS.WFS.GML.SLD等,只是国内相关书籍大家都懂的,特向Google大师请教,得一秘籍<Open Web Mapping> ...
- Fuel快速安装OpenStack
1 介绍 1.1 关于 Mirantis Mirantis,一家很牛逼的openstack服务集成商,他是社区贡献排名前5名中唯一一个靠软件和服务吃饭的公司(其他分别是Red Hat, HP, IBM ...
- Hibernate注解使用以及Spring整合
Hibernate注解使用以及Spring整合 原文转自:http://wanqiufeng.blog.51cto.com/409430/484739 (1) 简介: 在过去几年里,Hibernate ...
- Openstack Basic
html,body { } .CodeMirror { height: auto } .CodeMirror-scroll { } .CodeMirror-lines { padding: 4px 0 ...
- js变量搜索(先局部,后全局;先解析,后赋值)
var a=10; (function(){ alert(a); })() 变量先搜索局部,没有局部变量,会搜索全局变量 var a=10; (function(){ var a=20; alert( ...
- 7、SQL Server索引、表压缩
索引 什么是索引? 索引是一种磁盘上的数据结构,建立在表或视图的基础上.使用索引可以使数据的获取更快更高校,也会影响其他的一些性能,如插入或更新等. 索引主要分为两种类型:聚集索引和非聚集索引. 字典 ...
- Office OneNote 自动打开问题
你可能遇到如下问题: 在输入某些文本的时候,突然onenote自动打开 切换输入法,onenote自动打开 使用某些快捷键,onenote自动打开 最近我就遇到类似诡异的问题,使用了各种搜索引擎,都没 ...
- css之页面三列布局
左右两边宽度固定,中间自适应 第一种方法:左右两边绝对定位 html代码 <div class="left"></div> <div class=&q ...
- 通过innobackupex实现对MySQL的完整备份与还原
备份 新建一个用于存放备份的目录 mkdir /backup 执行以下命令: innobackupex --password=test /backup/ 执行完后你会看到“completed OK!” ...