hdu 1114 Piggy-Bank 完全背包
来源:互联网 发布:宾馆网络解决方案 编辑:程序博客网 时间:2024/06/08 11:24
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!
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!
310 11021 130 5010 11021 150 301 6210 320 4
Sample Output
完全背包;
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int x[100003];int y[100003];int dp[1000003];int main(){ int T; scanf("%d",&T); while(T--) { int l,r; scanf("%d%d",&l,&r); int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d%d",&x[i],&y[i]); } int w=r-l; for(int i=1;i<=w;i++) { dp[i]=1e9; }dp[0]=0; for(int i=1;i<=n;i++) { for(int j=y[i];j<=w;j++) { dp[j]=min(dp[j],dp[j-y[i]]+x[i]); } } if(dp[w]==1e9) printf("This is impossible.\n"); else printf("The minimum amount of money in the piggy-bank is %d.\n",dp[w]); }}
阅读全文
0 0
- hdu 1114 Piggy-Bank(完全背包)
- hdu 1114 Piggy-Bank【完全背包】
- hdu 1114 Piggy-Bank(完全背包)
- HDU 1114 Piggy-Bank (完全背包)
- HDU 1114 Piggy-Bank ( 完全背包 )
- HDU 1114 Piggy-Bank完全背包
- hdu 1114 Piggy-Bank(完全背包)
- hdu 1114 Piggy-Bank(完全背包)
- hdu 1114 Piggy-Bank(完全背包)
- hdu 1114 Piggy-Bank 完全背包
- HDU 1114 Piggy-Bank 完全背包
- HDU 1114 Piggy-Bank (完全背包)
- HDU 1114 Piggy-Bank (完全背包)
- hdu 1114 Piggy-Bank (完全背包)
- hdu 1114 Piggy-Bank 完全背包
- hdu 1114 Piggy-Bank (完全背包)
- hdu 1114 Piggy-Bank(完全背包)
- HDU 1114 Piggy-Bank (完全背包)
- 97. Interleaving String
- 素数判断的三种方法以及简单实现!
- 关于STm32加密【转】
- struts2标签以及获取parameter,request,session,application中的值
- 谈谈个人网站的建立(一)——建站历史和技术架构
- hdu 1114 Piggy-Bank 完全背包
- 《软技能-代码之外的生存指南》读后感
- 求最大子列和 (连续子串的最大值)
- Dijkstra模板(邻接矩阵)
- 笔试题
- 使用jTopo画网络拓扑图
- iOS学习笔记-095.彩票10——滑动移除控制器全屏实现
- 寻找最大连续子串和以及寻找最长数字串
- centos7+qt5开发环境配置