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 ...
 
随机推荐
- POJ - 3259
			
要判断是否有负的权值 #include<iostream> #include<stdio.h> #include<algorithm> #include<st ...
 - ionic 组件学习
			
利用css列表多选框: <div class="{{Conceal}}" > <ion-checkbox color="secondary" ...
 - Python3 Tkinter-Place
			
1.绝对坐标 from tkinter import * root=Tk() lb=Label(root,text='hello Place') lb.place(x=0,y=0,anchor=NW) ...
 - 11.22Daily Scrum(2)
			
人员 任务分配完成情况 明天任务分配 王皓南 实现网页上视频浏览的功能.研究相关的代码和功能.984 数据库测试 申开亮 实现网页上视频浏览的功能.研究相关的代码和功能.985 实现视频浏览的功能 王 ...
 - iOS开发NSDate详解
			
1. 用于创建NSDate实例的类方法有 + (id)date; 返回当前时间 + (id)dateWithTimeIntervalSinceNow:(NSTimeInterval)secs; 返回以 ...
 - <Effective C++>读书摘要--Resource Management<二>
			
<Item 15> Provide access to raw resources in resource-managing classes 1.You need a way to con ...
 - OSG学习:移动/缩放/旋转模型
			
移动和缩放以及旋转都是对矩阵进行操作,这些操作如果要叠加直接矩阵相乘就可以了. 下面的示例代码中,加入了四个bignathan,一个是默认加入在最中间,一个向上移2单位,一个是向下移2单位且缩放0.5 ...
 - 【week7】psp
			
本周psp 项目 内容 开始时间 结束时间 中断时间 净时间 2016/10/31 技术学习 看向数据库传入数据的代码 18:00 21:00 45 135 psp记录 将psp记录进电脑 21:20 ...
 - BAT批处理(六)
			
字符串处理 批处理有着具有非常强大的字符串处理能力,其功能绝不低于C语言里面的字符串函数集.批处理中可实现的字符串处理功能有:截取字符串内容.替换字符串特定字段.合并字符串.扩充字符串等功能.下面对这 ...
 - 【Docker 命令】- top命令
			
docker top :查看容器中运行的进程信息,支持 ps 命令参数. 语法 docker top [OPTIONS] CONTAINER [ps OPTIONS] 容器运行时不一定有/bin/ba ...