HDU1114 背包
Piggy-Bank
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 23354 Accepted Submission(s): 11824
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!
The minimum amount of money in the piggy-bank is 100.
This is impossible.
//多重背包,要最小价值,f初始化为无穷大(求最大价值时f[i]=-oo,f[0]=0),f[0]=0,
//求最小值即可。这里用inf初始化f,结果不对!
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int inf=0x7fffffff;
int f[];
struct coin{
int p,w;
double c;
}coins[];
void ComplitPack(int v,int w,int tol)
{
for(int i=v;i<=tol;i++){
f[i]=min(f[i],f[i-v]+w);
}
}
int main()
{
int t,n,s,e;
scanf("%d",&t);
while(t--){
scanf("%d%d",&s,&e);
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d%d",&coins[i].p,&coins[i].w);
coins[i].c=coins[i].p/coins[i].w;
}
for(int i=;i<=e-s;i++) f[i]=;
f[]=;
for(int i=;i<n;i++){
ComplitPack(coins[i].w,coins[i].p,e-s);
}
if(f[e-s]!=)
printf("The minimum amount of money in the piggy-bank is %d.\n",f[e-s]);
else printf("This is impossible.\n");
}
return ;
}
HDU1114 背包的更多相关文章
- HDU-1114(背包DP)
Piggy-Bank Problem Description Before ACM can do anything, a budget must be prepared and the necessa ...
- 简单的完全背包HDU1114
今天广州下雨啦,不过没关系啦,反正我最近也都在刷题学习算法. 昨天做了五题01背包,今天还是背包,不过是完全背包,估计做动态规划要持续好一段时间,一开始选了一道简单题目啦. HDU1114,看了小一段 ...
- hdu1114 完全背包
题意:给出钱罐的重量,然后是每种钱的价值和重量,问钱罐里最少可能有多少钱. 完全背包. 代码: #include<iostream> #include<cstdio> #inc ...
- hdu1114 Piggy-Bank (DP基础 完全背包)
链接:Piggy-Bank 大意:已知一只猪存钱罐空的时候的重量.现在的重量,已知若干种钱的重量和价值,猪里面装着若干钱若干份,求猪中的钱的价值最小值. 题解: DP,完全背包. g[j]表示组成重量 ...
- hdu1114(完全背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 分析:很裸的一道完全背包题,只是这里求装满背包后使得价值最少,只需初始化数组dp为inf:dp[ ...
- 完全背包hdu1114
https://vjudge.net/contest/68966#problem/F 初始化就行了:dp[0]=0: 这题还要刚好装满背包,输出时进行判断 #include<map> #i ...
- hdu1114 dp(完全背包)
题意:已知空钱罐质量和满钱罐质量(也就是知道钱罐里的钱的质量),知道若干种钱币每种的质量以及其价值,钱币都是无限个,问最少钱罐中有多少钱. 这个题在集训的时候学长给我们做过,所以你会做是应该的,由于已 ...
- kuangbin专题十二 HDU1114 Piggy-Bank (完全背包)
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU1114(完全背包装满问题)
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
随机推荐
- 【转】VSstudio中的一些宏
说明 $(RemoteMachine) 设置为“调试”属性页上“远程计算机”属性的值.有关更多信息,请参见更改用于 C/C++ 调试配置的项目设置. $(References) 以分号分隔的引用列表被 ...
- css多行文本溢出显示省略号(…)
text-overflow:ellipsis属性可以实现单行文本的溢出显示省略号(…).但部分浏览器还需要加宽度width属性. css代码: overflow: hidden; text-overf ...
- spark相关脚本解析
spark-shell/spark-submit/pyspark等关系如下: #spark-submit 逻辑: ########################################### ...
- CSS 之 选择器
CSS的常见选择器 一.简单选择器 Simple Selectors 选择器 含义 * 通用元素选择器,匹配任何元素 E 标签选择器,匹配所有使用E标签的元素 .info class选择器,匹配所有c ...
- C复合文字
C99之前,可以传递数组,但是没有所谓的数组常量可供传递,于是新增了复合文字. 普通数组声明方法: int d[2]={10,20}; 复合文字声明: 与数组名相同,常量同时代表元素的地址. (int ...
- Solium代码测试框架
Solium, 在solid中,Linter用于标识和修复样式&安全问题 //调用测试 solium -d contracts --fix 源代码名称:Solium 源代码网址:http:// ...
- POJ 2455 Secret Milking Machine(最大流+二分)
Description Farmer John is constructing a new milking machine and wishes to keep it secret as long a ...
- 在linux下PHP和Mysql环境搞事情
研发部门同事开发了一个接口管理辅助工具Shepherd,要求搭建在内网环境中,遇到点小问题记一下. 将开发的文件上传只web目录下,更改数据库ip,可以正常打开 登陆用户信息,此时需要连接数据库来验证 ...
- Python中的__future__
在Python中,你如果在某一个版本的Python想使用未来版本中的功能,可以使用如下语法实现: from __future__ import futurename 这条语句必须放在module文件的 ...
- 《剑指Offer》题四十一~题五十
四十一.数据流中的中位数 题目:如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值,那么中位数就是所有数值排序之后位于中间的数值.如果从数据流中读出偶数个数值,那么中位数就是所有数值排序之后中 ...