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. 微软BI 之SSIS 系列 - Lookup 中的字符串比较大小写处理 Case Sensitive or Insensitive

    开篇介绍 前几天碰到这样的一个问题,在 Lookup 中如何设置大小写不敏感比较,即如何在 Lookup 中的字符串比较时不区分大小写? 实际上就这个问题已经有很多人提给微软了,但是得到的结果就是 C ...

  2. Shell脚本编程实战一:创建按天备份的脚本工具

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/8241256.html 一:准备工作:创建归档目录 与  归档配置文件 归档目录:创建一个仓库目录,专门用于存放 ...

  3. C#:注册组件 (cmd)

    public class ComRegistor { public static string classID = "CLSID\\{479A1AAC-C148-40BB-9868-A977 ...

  4. Atitit.每周计划日程表 流程表v3

    Atitit.每周计划日程表 流程表 每周趋势总结 新特性聚合  最佳实践聚合. 上周总结 本度计划 检查于推进年度计划月度计划里程碑 检查于推进季度计划月度计划里程碑 上周Todo汇总结转.. 待报 ...

  5. 物联网架构成长之路(22)-Docker练习之Etcd服务搭建

    0. 前言 时隔多日,前段时间忙完一个可有可无的项目后,又进入摸鱼时间,没有办法,非互联网公司,就是闲得蛋疼.又开始了自学之路.以前入门过Docker,然后又很久没有看了,最近重新看了一下,推荐一下这 ...

  6. Fluent动网格【3】:DEFINE_CG_MOTION宏

    除了利用Profile进行运动指定之外,Fluent中还可以使用UDF宏来指定部件的运动.其中用于运动指定的宏主要有三个: DEFINE_CG_MOTION DEFINE_GEOM DEFINE_GR ...

  7. --save与--save-dev的区别

    --save安装的包会在生产和开发环境中都使用: --save-dev的包只在开发环境中使用,在生产环境中就不需要这个包了,不再打包:

  8. 4. Tensorflow的Estimator实践原理

    1. Tensorflow高效流水线Pipeline 2. Tensorflow的数据处理中的Dataset和Iterator 3. Tensorflow生成TFRecord 4. Tensorflo ...

  9. Unity5 AssetBundle系列——基本流程

    Unity5的AssetBundle修改比较大,所以第一条建议是:忘掉以前的用法,重新来!要知道,Unity5已经没办法加载2.x 3.x的bundle包了…体会一下Unity5 AssetBundl ...

  10. 解决:android源码同步repo sync 时出现的fatal:duplicate path错误

    问题重现: 解决方法: 1.删除android项目里隐藏的 .repo 文件夹中除了以下几个文件夹的其他文件及文件夹 2.重新初始化android项目 repo init -u https//gith ...