HDU 1114(没有变形的完全背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114
Piggy-Bank
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 32136 Accepted Submission(s): 15965
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!
dp[0]=0;
#include<bits/stdc++.h> #define max_v 10005 using namespace std; int v[max_v],w[max_v]; int dp[max_v]; int main() {int t;scanf("%d",&t);while(t--){int x1,x2,c;scanf("%d %d",&x1,&x2);c=abs(x1-x2);int n;scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d %d",&v[i],&w[i]);}memset(dp,0x3f,sizeof(dp));//无穷大 //要求恰好装满背包dp[0]=0;for(int i=0;i<n;i++){for(int j=w[i];j<=c;j++){dp[j]=min(dp[j],dp[j-w[i]]+v[i]);}}if(dp[c]==dp[max_v-2]){printf("This is impossible.\n");}else{printf("The minimum amount of money in the piggy-bank is %d.\n",dp[c]);}}return 0; }
转载于:https://www.cnblogs.com/yinbiao/p/9093017.html
HDU 1114(没有变形的完全背包)相关推荐
- D - 猪钱罐 HDU - 1114
D - 猪钱罐 HDU - 1114 在 ACM 能够开展之前,必须准备预算,并获得必要的财力支持.该活动的主要收入来自于 Irreversibly Bound Money (IBM).思路很简单.任 ...
- HDU 1114—Piggy-Bank(储蓄罐)(完全背包)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 题意 开始时输入T,代表一共有T个样例. 对于每一个样例,第一行给出E与F(1<=E,F< ...
- HDU 3033 I love sneakers! (分组背包变形)
题目大意:xx去买鞋,有k种牌子,然后给出n双鞋,每双鞋有它属于的牌子.价格.收藏价值.xx认为他不差钱,要求每种鞋子买一双.但实际上他只有m毛钱,问能否买到符合xx要求的鞋,能找到的话输出最大的收藏 ...
- HDU 1114 Piggy-Bank 猪仔储钱罐(完全背包)
题意: 给定一个存钱罐中要存硬币,知道空罐的重量和欲装满的重量,是否能装入?若能,打印最小价值.(注:能装的硬币重量一定刚刚好,里面的总价值要达到最小) 输入: 包含了T个测试例子,在第一行给出.接下 ...
- hdu 1114 完全背包
传送门 Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDU 1114 iggy-Bank(完全背包)
水 给出小猪钱罐的重量和装满钱后的重量,然后是几组数据,每组数据包括每种钱币的价值与重量 要求出重量最少能装满钱罐时的最大价值 1 #include<iostream> 2 #includ ...
- Piggy-Bank HDU - 1114(多重背包)
在 ACM 能够开展之前,必须准备预算,并获得必要的财力支持.该活动的主要收入来自于 Irreversibly Bound Money (IBM).思路很简单.任何时候,某位 ACM 会员有少量的钱时 ...
- HDU 1114 Piggy-Bank 存钱罐
原题: http://acm.hdu.edu.cn/showproblem.php?pid=1114 题目: Piggy-Bank Time Limit: 2000/1000 MS (Java/Oth ...
- hdu 5616 Jam's balance 正反背包+转换
http://acm.hdu.edu.cn/showproblem.php?pid=5616 思路 题目中蕴含着两种需要计算的重量 1. 从所有的砝码中挑出任意种 2.(转换的思想)在天平的两端都挑出 ...
最新文章
- 关于write()和fsync()
- linux avd 界面,Android Studio创建AVD
- Sql Server 监控 Job 执行情况
- Shell脚本之一 Shell脚本简介
- PerlRegex堆栈溢出的问题
- 【斐波拉切数列第N项】
- 无聊特意去拍月亮。呵呵
- openSUSE 安装 Torch
- 电力电子仿真软件对比分析
- z世代中的z是什么意思_开放是与Z世代合作的关键
- 关于WPF你应该知道的2000件事
- 如何设置电脑的保护色?
- MOS 的TJ TA TC和功耗之类的计算
- Notepad++安装HexEditor插件
- 防范于未“燃”|涂鸦智慧社区推出“黑科技”,电瓶车禁入电梯智慧方案
- 使用苹果发布证书打包好的ipa如何安装到ios手机上测试
- matlab pi表示,matlab中pi是什么意思
- 信息系统项目管理师速记 - 十大知识领域
- PHP实现的日志收集系统
- 大咖实录|漆远蚂蚁金服首席数据科学家等演讲实录
热门文章
- Bit-Z收不到邮箱验证码怎么办(如何添加Bit-Z至邮箱白名单?)
- An Introduction to Hashing in the Era of Machine Learning
- 【进阶】从linux到android,进程的方方面面
- 深入理解Android的startservice和bindservice
- 网站假设php,PHP个人网站架设连环讲(一)
- JZOJ 100045. 【NOIP2017提高A组模拟7.13】好数
- ubuntu14.04安装完ros后常用的其他安装
- 3d 强制添加脚本_每日学点---Jenkins执行脚本权限问题
- ultraedit 运行的是试用模式_Wings面向企业级的单元测试用例自动编码引擎
- 电脑屏幕保护怎么取消_怎么监控员工电脑?老板如何知道员工上班在干什么?...