练习三 Problem R

原创 2016年05月31日 20:25:58

Problem 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. <br><br>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! <br>

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

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

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.

题意:称出背包装物品前后的重量,求最小价值。


思路:将dp的值初始化为无穷大,就有第i件物品可选可不选,根据这个可以计算出所有情况,最后求最优值。


感想:完全背包问题,注意j的值为从小到大。


代码:


版权声明:本文为博主原创文章,未经博主允许不得转载。

指针练习--变量交换H

Description 注:本题只需要提交填写部分的代码 用指针变量对两个整数按从小到大排序。 #include int main() {     int *p1,*p2,*p;     int a...
  • l769255844
  • l769255844
  • 2015年12月27日 16:56
  • 331

专题三 Problem R

一、题目编号:           1018 二、简单题意:        不知道存钱罐里面有多少钱,知道存钱罐的重量和各类钱币的重量,求出存钱罐里面最少有多少钱。 三、解题思路形成过程 ...
  • ML_ACM
  • ML_ACM
  • 2016年05月31日 20:46
  • 142

r入门练习(三)

R语言学习,后更答案。 第七章 字串符和因子 7.1   字符串 字符向量中的每个元素都是字符串,文本的基本单位是字符向量。字符向量可用c 函数创建。我们可以用单引号或双引号把字符串引用起来,只要...
  • Sumri_Lin
  • Sumri_Lin
  • 2017年10月30日 18:52
  • 111

练习三 Problem A

原题: Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max...
  • ibingyu
  • ibingyu
  • 2016年05月16日 17:55
  • 906

练习三 Problem J

题目: 有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?   Input 输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每...
  • ibingyu
  • ibingyu
  • 2016年05月27日 21:46
  • 97

练习三 Problem N

Problem Description 我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目。比如,一条折线可以将平面分成两部分,两条折线最多可以将平面...
  • ibingyu
  • ibingyu
  • 2016年05月28日 19:39
  • 177

练习三 Problem C

题目: Problem Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is...
  • ibingyu
  • ibingyu
  • 2016年05月16日 17:41
  • 116

练习三 Problem V

Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that th...
  • ibingyu
  • ibingyu
  • 2016年05月29日 11:21
  • 116

练习三 Problem W

Problem Description Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了。要申请国外的任何大学,你都要交纳一定的申请费...
  • ibingyu
  • ibingyu
  • 2016年05月31日 19:34
  • 152

练习三 Problem E

Problem Description A group of researchers are designing an experiment to test the IQ of a monkey. T...
  • ibingyu
  • ibingyu
  • 2016年05月28日 20:51
  • 146
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:练习三 Problem R
举报原因:
原因补充:

(最多只允许输入30个字)