传送门

Piggy-Bank

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24208    Accepted Submission(s): 12253

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.

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
Central Europe 1999
Recommend
Eddy   |   We have carefully selected several similar problems for you:  2191 1203 1059 1074 1024 

这是一个关于完全背包的题目,题意是有一个存钱罐,没有装钱币的时候质量为e克,装满的时候质量为f克,有n种钱币,价值分别为p[i],质量为w[i],求把存钱罐装满的钱最少为多少。

完全背包跟01背包就只有一个内循环是相反的,其他都一样,这样套着模板来就很容易理解啦!


#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <cstring>
#include <queue>
#include <list>
#include <cstdio>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <functional>
using namespace std;#define pi acos(-1)
#define endl '\n'
#define me(x) memset(x,0,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0);
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
//const int dx[]={-1,0,1,0,-1,-1,1,1};
//const int dy[]={0,1,0,-1,1,-1,1,-1};
const int maxn=1e3+5;
const int maxx=1e6+100;
const double EPS=1e-7;
const int MOD=1000000007;
#define mod(x) ((x)%MOD);
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
//typedef tree<pt,null_type,less< pt >,rb_tree_tag,tree_order_statistics_node_update> rbtree;
/*lch[root] = build(L1,p-1,L2+1,L2+cnt);rch[root] = build(p+1,R1,L2+cnt+1,R2);中前*/
/*lch[root] = build(L1,p-1,L2,L2+cnt-1);rch[root] = build(p+1,R1,L2+cnt,R2-1);中后*/
long long gcd(long long a , long long b){if(b==0) return a;a%=b;return gcd(b,a);}int dp[maxx];
struct node
{int x,y;
}Q[maxn];
int main()
{int t;cin>>t;while(t--){int a,b;cin>>a>>b;int w=b-a;int n;cin>>n;for(int i=0;i<n;i++)cin>>Q[i].x>>Q[i].y;fill(dp,dp+w+1,INF);dp[0]=0;for(int i=0;i<n;i++)for(int j=Q[i].y;j<=w;j++)dp[j]=min(dp[j],dp[j-Q[i].y]+Q[i].x);if(dp[w]==INF)  printf("This is impossible.\n");else  printf("The minimum amount of money in the piggy-bank is %d.\n",dp[w]);}
}

hdu 1114 完全背包相关推荐

  1. D - 猪钱罐 HDU - 1114

    D - 猪钱罐 HDU - 1114 在 ACM 能够开展之前,必须准备预算,并获得必要的财力支持.该活动的主要收入来自于 Irreversibly Bound Money (IBM).思路很简单.任 ...

  2. HDU 1114(没有变形的完全背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 Piggy-Bank Time Limit: 2000/1000 MS (Java/Others ...

  3. HDU 1114—Piggy-Bank(储蓄罐)(完全背包)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 题意 开始时输入T,代表一共有T个样例. 对于每一个样例,第一行给出E与F(1<=E,F< ...

  4. HDU 1114 Piggy-Bank 猪仔储钱罐(完全背包)

    题意: 给定一个存钱罐中要存硬币,知道空罐的重量和欲装满的重量,是否能装入?若能,打印最小价值.(注:能装的硬币重量一定刚刚好,里面的总价值要达到最小) 输入: 包含了T个测试例子,在第一行给出.接下 ...

  5. HDU 1114 iggy-Bank(完全背包)

    水 给出小猪钱罐的重量和装满钱后的重量,然后是几组数据,每组数据包括每种钱币的价值与重量 要求出重量最少能装满钱罐时的最大价值 1 #include<iostream> 2 #includ ...

  6. Piggy-Bank HDU - 1114(多重背包)

    在 ACM 能够开展之前,必须准备预算,并获得必要的财力支持.该活动的主要收入来自于 Irreversibly Bound Money (IBM).思路很简单.任何时候,某位 ACM 会员有少量的钱时 ...

  7. HDU 1114 Piggy-Bank 存钱罐

    原题: http://acm.hdu.edu.cn/showproblem.php?pid=1114 题目: Piggy-Bank Time Limit: 2000/1000 MS (Java/Oth ...

  8. hdu 3732(01背包转多重背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3732 思路:这么大的数据,用01背包肯定会TLE的,01背包转多重背包..最多也就11*11=121件 ...

  9. HDU 1114 Piggy-Bank 简单DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 题目大意:完全背包问题,不过这次是求的最小值. 解题思路:首先是初始化问题,其次就是状态转移的时 ...

最新文章

  1. 剖析Focal Loss损失函数: 消除类别不平衡+挖掘难分样本 | CSDN博文精选
  2. Mybatis指定日志输出实现
  3. 051_Array对象
  4. srv.sys蓝屏解决补丁_电脑蓝屏重启怎么解决?
  5. 教你如何阅读Oracle数据库官方文档
  6. boost::geometry模块自定义坐标系示例
  7. pandas保存为excel,同时设置保存的excel的样式
  8. 轻量级的java HTTP Server——NanoHttpd
  9. segnet和unet区别_SegNet图像分割网络直观详解
  10. oracle材料成本发票价差,ORACLE ERP 成本核算会计信息归纳
  11. 操作日志注解aspectj-autoproxy
  12. 北京航空航天大学计算机系考研复试上机真题及答案---2014
  13. Python|用turtle画笔制作奥运五环
  14. Hadoop学习篇(一)——初识Hadoop Hadoop单机配置
  15. 人听到坏消息的反应_如何应对坏消息,正确传达坏消息的七个方法
  16. 看了让人吐血的146个脑筋急转弯问题
  17. npz、npy文件生成与读取
  18. php两个相差为2的素数,重发系列证明之五:相差2k=6s+2的素数对是无穷多的
  19. Java开发常见面试题详解(LockSupport,AQS,Spring循环依赖,Redis)
  20. geoserver的安装步骤

热门文章

  1. 咬文嚼字 | 信息化和数字化的本质区别是什么?
  2. PDPS 服务器型Imtools的安装与最新一期许可证分享及替换方法
  3. chrome谷歌浏览器调试微信H5页面
  4. PySide+PyDesigner出现错误:This application failed to start because no Qt platform plugin could be initia
  5. Spark全套知识体系,终于搞到了!
  6. linux网络编程 epoll水平触发、边沿触发、反应堆模型、线程池思想
  7. 琢石成器之自动化去广告神器
  8. 从空间中理解线性代数
  9. 使用BERT fine-tuning 用于推特情感分析
  10. 心血来潮,今天也搞个BLOG