题解报告:hdu 1114 Piggy-Bank(完全背包恰好装满)
Problem Description
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
Output
Sample Input
Sample Output
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
int T,E,F,N,W,v,w,dp[];
int main(){
while(cin>>T){
while(T--){
memset(dp,0x3f,sizeof(dp));dp[]=;//空罐时的最小价值为0
cin>>E>>F>>N;W=F-E;//完全背包的总重量
for(int i=;i<=N;i++){
cin>>v>>w;//v是币值,w是该种币的重量
for(int j=w;j<=W;j++)dp[j]=min(dp[j],dp[j-w]+v);
}
if(dp[W]!=INF)cout<<"The minimum amount of money in the piggy-bank is "<<dp[W]<<'.'<<endl;
else cout<<"This is impossible."<<endl;
}
}
return ;
}
题解报告:hdu 1114 Piggy-Bank(完全背包恰好装满)的更多相关文章
- HDU 1114 Piggy-Bank(判断是否恰好装满的背包)
其实这道题在寒假自学训练赛的时候就做过,不过感觉现在的理解跟当时真的不一样,大一半年过去了,变了这么多,我们都在进步,一回头便走出了这么远... 好了,题目很简单,一个背包,装不满做一个标记就行了 # ...
- HDOJ(HDU).1114 Piggy-Bank (DP 完全背包)
HDOJ(HDU).1114 Piggy-Bank (DP 完全背包) 题意分析 裸的完全背包 代码总览 #include <iostream> #include <cstdio&g ...
- HDU - 1114 Piggy-Bank 完全背包(背包恰好装满)
Piggy-Bank Before ACM can do anything, a budget must be prepared and the necessary financial support ...
- QDUOJ 分辣条-01背包恰好装满情况
分辣条 发布时间: 2016年6月26日 20:36 最后更新: 2016年6月26日 20:37 时间限制: 1000ms 内存限制: 128M 描述 “你喝的酸奶是我买的,辣条也是我买 ...
- HDU-1114 完全背包+恰好装满问题
B - Piggy-Bank Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Subm ...
- HDU 1114 Piggy-Bank(完全背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 题目大意:根据储钱罐的重量,求出里面钱最少有多少.给定储钱罐的初始重量,装硬币后重量,和每个对应 ...
- HDU - 1114 Piggy-Bank 【完全背包】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1114 题意 给出一个储钱罐 不知道里面有多少钱 但是可以通过重量来判断 先给出空储钱罐的重量 再给出装 ...
- hdu(1114)——Piggy-Bank(全然背包)
唔..近期在练基础dp 这道题挺简单的(haha).可是我仅仅想说这里得注意一个细节. 首先题意: 有T组例子,然后给出储蓄罐的起始重量E,结束重量F(也就是当它里面存满了零钱的时候).然后给你一个数 ...
- HDU 1114 Piggy-Bank ——(完全背包)
差不多是一个裸的完全背包,只是要求满容量的最小值而已.那么dp值全部初始化为inf,并且初始化一下dp[0]即可.代码如下: #include <stdio.h> #include < ...
随机推荐
- 【转】apache storm 内置的定时机制
原文:http://www.cnblogs.com/kqdongnanf/p/4778672.html ------------------------------------------------ ...
- 鼠标放上去Div旋转特效代码
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- android 自己定义水平和圆形progressbar 仅仅定义一些style就能够
效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/diss ...
- js中window.onload 与 jquery中$(document.ready()) 測试
js中window.onload 与 jquery中$(document.ready())差别,验证代码例如以下(调换js代码和Jquer代码书写顺序測试.执行结果一样.因此与代码书写位置没关系): ...
- Redis管理key命令
1 DEL key该命令用于在 key 存在时删除 key. 2 DUMP key 序列化给定 key ,并返回被序列化的值. 3 EXISTS key 检查给定 key 是否存在. 4 EXPIRE ...
- 在线生成32位和16位大小写MD5密文
MD5是一种不可逆的加密算法,全称是Message-Digest Algorithm 5(信息-摘要算法).是当前计算机领域用于确保信息传输完整一致而广泛使用的散列算法之一. MD5的典型应用是对一段 ...
- 【网站支付PHP篇】thinkPHP集成支付宝支付(担保交易)
目录 系列说明 开发环境 部署支付宝 支付请求 支付宝返回处理 系列说明 最近在帮朋友的系统安装支付模块(兑换网站积分),现在总结一些开发心得,希望对大家有用.这个系列会讲以下第三方支付平台的集成: ...
- 2016/2/26 <marquee></marquee>实现多种滚动效果
页面的自动滚动效果,可由javascript来实现,但是有一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制.使用marquee标记 ...
- docker大全集
1,什么是docker docker 最初是dotCloud公司创始人 Solomon Hykes 在法国期间发起的一个公司内部醒目,于 2013年 3 月以 Apache 2.0 授权协议开源, 主 ...
- ubuntu字符界面下显示中文和调整分辨率
1.sudo apt-get install zhcon 2.vi /etc/zhcon.conf 修改下面两行 x_resolution 1024 y_resolution 768 完成这两步后在 ...