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

完全背包问题

#include<iostream>
using namespace std;
const int MAX=10050; int f[MAX],w[MAX];//f数组记录硬币的面值,w数组记录硬币的重量
int k[MAX];//k数组用来记录最小取值 int main()
{
int num,i;
cin>>num;
while(num--)
{
int e,t,temp;
int cases;
cin>>e>>t>>cases;
temp=t-e; for(i=0;i<cases;i++)
cin>>f[i]>>w[i]; k[0]=0;//重量为0的钱币价值为0,即没有钱币 for(i=1;i<=temp;i++)
{
k[i]=999999999;
} for(i=0;i<cases;i++)
for(int m=w[i];m<=temp;m++)
if(k[m-w[i]]+f[i]<k[m])
k[m]=k[m-w[i]]+f[i]; if(k[temp]==999999999)
printf("This is impossible.\n");
else
printf("The minimum amount of money in the piggy-bank is %d.\n",k[temp]);
}
//system("pause");
return 0; }

ZOJ Problem Set - 2014 Piggy-Bank【完全背包】的更多相关文章

  1. ZOJ Problem Set - 1365 Mileage Bank

    题目不难,主要说下这道题目在输入终止上的问题: 题目要求当输入为0时一次case结束,当输入为#时整个输入全部结束,可以用如下格式解决 while(scanf("%s",str)! ...

  2. 浙大月赛ZOJ Monthly, August 2014

    Abs Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Alice and Bob is playing a ga ...

  3. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  4. ZOJ Problem Set - 1025解题报告

    ZOJ Problem Set - 1025 题目分类:基础题 原题地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=10 ...

  5. ZOJ Problem Set - 3829Known Notation(贪心)

    ZOJ Problem Set - 3829Known Notation(贪心) 题目链接 题目大意:给你一个后缀表达式(仅仅有数字和符号),可是这个后缀表达式的空格不幸丢失,如今给你一个这种后缀表达 ...

  6. ZOJ Problem Set - 2563 Long Dominoes 【如压力dp】

    称号:ZOJ Problem Set - 2563 Long Dominoes 题意:给出1*3的小矩形.求覆盖m*n的矩阵的最多的不同的方法数? 分析:有一道题目是1 * 2的.比較火.链接:这里 ...

  7. ZOJ Problem Set - 3593 拓展欧几里得 数学

    ZOJ Problem Set - 3593 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3593 One Person ...

  8. ZOJ Problem Set - 2297 Survival 【状压dp】

    题目:ZOJ Problem Set - 2297 Survival 题意:给出一些怪,有两个值,打他花费的血和能够添加的血,然后有一个boss,必须把小怪全部都打死之后才干打boss,血量小于0会死 ...

  9. 135 - ZOJ Monthly, August 2014

    135 - ZOJ Monthly, August 2014 A:构造问题,推断序列奇偶性.非常easy发现最小值不是1就是0.最大值不是n就是n - 1,注意细节去构造就可以 E:dp.dp[i][ ...

随机推荐

  1. Spring ActiveMQ 整合(三): 确认机制ACK(收到消息后,应该有一个回应也就是确认答复)

    https://blog.csdn.net/dly1580854879/article/details/68490197

  2. PL/SQL学习笔记之函数

    一:函数 函数与过程的最大不同就是,函数有返回值.适用于需要返回结果的场景. 二:创建函数 CREATE [OR REPLACE] FUNCTION function_name [(parameter ...

  3. list与Set、Map区别及适用场景

    1.List,Set都是继承自Collection接口,Map则不是 2.List特点: 元素有放入顺序,元素可重复 ,Set特点:元素无放入顺序,元素不可重复,重复元素会覆盖掉,(注意:元素虽然无放 ...

  4. 用命令让vbox的虚拟硬盘文件转换成vmware的vmdk

    VirtualBox的生成备份功能只是个系统还原点 这个生成备份功能备份速度非常快,其实它并不是备份,而是相当于xp系统中的建立系统还原点.但是要注意的是如果你的虚拟硬盘文件(***.vdi)在别的V ...

  5. Adobe Photoshop CC2019中文破解版

    今天突发兴致玩PS, 之前安装的是CS6, 下载安装色相环插件后 先采用拷贝文件夹的方式将Coolorus放到plug-in下, 重启发现窗口>扩展程序 这项是灰色的. 于是采用安装coolor ...

  6. dup2替换

    今天看APUE上一道题,要求不能用fcnt1来替换dup1. 刚开始的思路是dup一个,测试发现与期望的不一致就马上关闭,发现遇到无限循环,刚才想了下,才发现一旦close掉,再次dup仍然是分配最小 ...

  7. C# 使用NLog记录日志入门操作

    环境:win7 64位, VS2010 1.首先用VS2010创建命令行工程NLogDemo 2.在程序包管理器控制台中输入:Install-Package NLog -Version 4.4.12 ...

  8. ajax之async属性

    Ajax请求中的async:false/true的作用 官方的解释是:http://api.jquery.com/jQuery.ajax/ async Boolean Default: true By ...

  9. 【Unity】Protobuf的使用与常见问题

    Protobuf的使用流程 protobuf参考教程:https://www.jianshu.com/p/b135676dbe8d 手写.proto文件后,用CMD命令行运行protoc.exe编译器 ...

  10. 教你怎么上传本地代码到github

    第一步:建立git仓库 cd到你的本地项目根目录下,执行git命令 git init 第二步:去github上创建自己的Repository,创建完成后拿到创建的仓库的https地址 第三步:将本地的 ...