POJ1384Piggy-Bank[完全背包]
Piggy-Bank
Description Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (IBM). The idea behind is simple. Whenever some ACM member has any small money, he takes all the coins and throws them into a piggy-bank. You know that this process is irreversible, the coins cannot be removed without breaking the pig. After a sufficiently long time, there should be enough cash in the piggy-bank to pay everything that needs to be paid.
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 The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing two integers E and F. They indicate the weight of an empty pig and of the pig filled with coins. Both weights are given in grams. No pig will weigh more than 10 kg, that means 1 <= E <= F <= 10000. On the second line of each test case, there is an integer number N (1 <= N <= 500) that gives the number of various coins used in the given currency. Following this are exactly N lines, each specifying one coin type. These lines contain two integers each, Pand W (1 <= P <= 50000, 1 <= W <=10000). P is the value of the coin in monetary units, W is it's weight in grams.
Output Print exactly one line of output for each test case. The line must contain the sentence "The minimum amount of money in the piggy-bank is X." where X is the minimum amount of money that can be achieved using coins with the given total weight. If the weight cannot be reached exactly, print a line "This is impossible.".
Sample Input 3 Sample Output The minimum amount of money in the piggy-bank is 60. Source |
裸题
注意容量是正序,01背包打顺手了
//
// main.cpp
// poj1384
//
// Created by Candy on 9/21/16.
// Copyright © 2016 Candy. All rights reserved.
// #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int V=1e4+,INF=1e9;
int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int t,E,F,v,n;
int f[V],p,w;
int main(int argc, const char * argv[]) {
t=read();
while(t--){
E=read();F=read();n=read();
v=F-E;
for(int i=;i<=v;i++) f[i]=INF;
for(int i=;i<=n;i++){
p=read();w=read();
for(int j=w;j<=v;j++)
f[j]=min(f[j],f[j-w]+p);
}
if(f[v]==INF) printf("This is impossible.\n");
else printf("The minimum amount of money in the piggy-bank is %d.\n",f[v]);
} return ;
}
POJ1384Piggy-Bank[完全背包]的更多相关文章
- BZOJ 1531: [POI2005]Bank notes( 背包 )
多重背包... ---------------------------------------------------------------------------- #include<bit ...
- bzoj1531: [POI2005]Bank notes(多重背包)
1531: [POI2005]Bank notes Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 521 Solved: 285[Submit][Sta ...
- 【多重背包小小的优化(。・∀・)ノ゙】BZOJ1531-[POI2005]Bank notes
[题目大意] Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我们想要凑出 ...
- 【bzoj1531】[POI2005]Bank notes 多重背包dp
题目描述 Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我们想要凑出面值 ...
- bzoj 1531 Bank notes 多重背包/单调队列
多重背包二进制优化终于写了一次,注意j的边界条件啊,疯狂RE(还是自己太菜了啊啊)最辣的辣鸡 #include<bits/stdc++.h> using namespace std; in ...
- 2018.09.08 bzoj1531: [POI2005]Bank notes(二进制拆分优化背包)
传送门 显然不能直接写多重背包. 这题可以用二进制拆分/单调队列优化(感觉二进制好写). 所谓二进制优化,就是把1~c[i]拆分成20,21,...2t,c[i]−2t+1+1" role= ...
- bzoj1531: [POI2005]Bank notes
Description Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我 ...
- DSY1531*Bank notes
Description Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我 ...
- Hdu 2955 Robberies 0/1背包
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- Poj 1276 Cash Machine 多重背包
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26172 Accepted: 9238 Des ...
随机推荐
- Windows安装apache2.4
The primary Windows platform for running Apache 2.4 is Windows 2000 or later. Always obtain and inst ...
- [DeviceOne开发]-白板的示例
一.简介 该demo通过do_Painterview这个组件实现画板的基本功能,模仿的是Appstore上的叫“白板”的应用,可以更改字体颜色,字体粗细,然后用手指进行绘制,可以回退,清屏,保存到相册 ...
- html5音频和视频标签
在html5之前的版本中如果想要在网页中插入音频和视频必须要安装插件才可以,比如最常见的flash插件.很多人在刚安装一款浏览器的时候都会遇到浏览器建议安装flash插件,在移动端也是如此.如果想要在 ...
- 刷新拜拜~gulp-livereload
早就想要自动自动自动刷新了啊,曾经用grunt实现过,但是是yeoman建好的..其中很多任务我是用不到的啊,为了干净还是得要自己写啊哈哈(现在我只想要自动刷新). 首先node是必须的了-就不说怎么 ...
- SharePoint 2013 日历视图兼容性问题
在IE11上访问SharePoint 2013 calendar视图,发现加入兼容性视图以后访问,正常,如下图: 不加入兼容性视图IE11访问,出现兼容性问题,如下图: 因为有些环境有问题,有些环境没 ...
- 自定义JSP标签库及Properties使用
自定义JSP标签库及Properties使用 自定义JSP标签 自定义JSP标签技术是在JSP 1.1版本中才出现的,它支持用户在JSP文件中自定义标签,这样可以使JSP代码更加简洁. 这些可重用的标 ...
- umeng 渠道统计ios
1. 使用前提:需要在工程中添加依赖框架:AdSupport.framework 和 Security.framework 2.在AppDelegate.m文件中的-(BOOL)application ...
- Android 采用post方式提交数据到服务器
接着上篇<Android 采用get方式提交数据到服务器>,本文来实现采用post方式提交数据到服务器 首先对比一下get方式和post方式: 修改布局: <LinearLayout ...
- 【代码笔记】iOS-钢琴小游戏
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> //加入头文件 #import <AudioTool ...
- 通过跳板机建立信任,对多个tomcat服务统一安装部署(shell编写)
unifyDeploy 自动化统一安装部署 系统版本: unifyDeploy0.1 文件编号: 0.1 发布日期: 2014-06-26 编 制: WangYong 版权所有 内部资料注意保密 ...