Piggy-Bank
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 10787   Accepted: 5258

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
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

裸题

注意容量是正序,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[完全背包]的更多相关文章

  1. BZOJ 1531: [POI2005]Bank notes( 背包 )

    多重背包... ---------------------------------------------------------------------------- #include<bit ...

  2. bzoj1531: [POI2005]Bank notes(多重背包)

    1531: [POI2005]Bank notes Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 521  Solved: 285[Submit][Sta ...

  3. 【多重背包小小的优化(。・∀・)ノ゙】BZOJ1531-[POI2005]Bank notes

    [题目大意] Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我们想要凑出 ...

  4. 【bzoj1531】[POI2005]Bank notes 多重背包dp

    题目描述 Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我们想要凑出面值 ...

  5. bzoj 1531 Bank notes 多重背包/单调队列

    多重背包二进制优化终于写了一次,注意j的边界条件啊,疯狂RE(还是自己太菜了啊啊)最辣的辣鸡 #include<bits/stdc++.h> using namespace std; in ...

  6. 2018.09.08 bzoj1531: [POI2005]Bank notes(二进制拆分优化背包)

    传送门 显然不能直接写多重背包. 这题可以用二进制拆分/单调队列优化(感觉二进制好写). 所谓二进制优化,就是把1~c[i]拆分成20,21,...2t,c[i]−2t+1+1" role= ...

  7. bzoj1531: [POI2005]Bank notes

    Description Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我 ...

  8. DSY1531*Bank notes

    Description Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我 ...

  9. Hdu 2955 Robberies 0/1背包

    Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  10. Poj 1276 Cash Machine 多重背包

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

随机推荐

  1. github上比较全的知识

    https://github.com/hawx1993/github-FE-project

  2. swift学习笔记之-访问控制

    //访问控制 import UIKit /*访问控制(Access Control) 1.访问控制可以限定其他源文件或模块中的代码对你的代码的访问级别.这个特性可以让我们隐藏代码的一些实现细节,并且可 ...

  3. 从客户端(?)中检测到有潜在危险的 Request.Path 值 的解决方案

    public ActionResult A(string title) { return Redirect("B"+((String.IsNullOrEmpty(title))?& ...

  4. OpenGL中旋转平移缩放等变换的顺序对模型的影响

    l 前提: 0x01. 假设绘制顶点的语句为Draw Array,变换的语句(旋转.平移.缩放)为M,而 M0; M1; M2; Draw Array; 则称对Array先进行M2再进行M1.M0 0 ...

  5. web页面直接跳转至其他页面

    <script type="text/javascript">window.location.herf="../../XXXXX.aspx";< ...

  6. ae_将面积小于1500的Feature同附近Feature进行合并

    private void 合并1500图斑ToolStripMenuItem_Click(object sender, EventArgs e) { /* *将图层中面积小于1500的图斑与之相同BS ...

  7. charset的获取方法

      1.解析http请求的返回值: 2.通过解析html的meta标签里面的数据: 3.通过cpdetector(java环境下)来自动验证: ---------------------------- ...

  8. 应用代理 socket TCP协议 的资料

    http://blog.csdn.net/guowake/article/details/6615728 Linux下高并发socket最大连接数所受的各种限制 http://stackoverflo ...

  9. android 浅谈Aidl 通讯机制

    服务端: 首先是编写一个aidl文件,注意AIDL只支持方法,不能定义静态成员,并且方法也不能有类似public等的修饰符:AIDL运行方法有任何类型的参数和返回值,在java的类型中,以下的类型使用 ...

  10. Spring MVC 原理小结

    主要由DispatcherServlet.处理器映射.处理器.视图解析器.视图组成   1.DispatcherServlet接收到一个HTTP请求,根据对应配置文件中的处理机映射,找到处理器(Han ...