HDU1114(完全背包装满问题)
Piggy-Bank
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 19849    Accepted Submission(s): 10086
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!
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
const int MAXN=;
int n,W;
int v[MAXN],w[MAXN];
int dp[MAXN];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int e,f;
scanf("%d%d",&e,&f);
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&v[i],&w[i]);
}
W=f-e;
for(int i=;i<MAXN;i++)
{
dp[i]=INF;//大前提:背包装满.因为求获得的价值最小,所以需要将dp初始化正无穷.若求价值最大,则将dp初始化为负无穷
}
dp[]=;//背包需要装满,则将dp[0]初始化为0
for(int i=;i<n;i++)
{
for(int j=w[i];j<=W;j++) //完全背包:逆序
dp[j]=min(dp[j-w[i]]+v[i],dp[j]);//求最小的价值
}
if(dp[W]==INF)
{
printf("This is impossible.\n");
}
else
{
printf("The minimum amount of money in the piggy-bank is %d.\n",dp[W]);
}
} return ;
}
HDU1114(完全背包装满问题)的更多相关文章
- HDU-1114  完全背包+恰好装满问题
		B - Piggy-Bank Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Subm ... 
- hdu1114 完全背包
		题意:给出钱罐的重量,然后是每种钱的价值和重量,问钱罐里最少可能有多少钱. 完全背包. 代码: #include<iostream> #include<cstdio> #inc ... 
- 01背包模板、全然背包 and 多重背包(模板)
		转载请注明出处:http://blog.csdn.net/u012860063 贴一个自觉得解说不错的链接:http://www.cppblog.com/tanky-woo/archive/2010/ ... 
- hdu3496  二维01背包
		题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3496 //刚看题目以为是简单的二维01背包,but,,有WA点.. 思路:题中说,只能买M ... 
- Partial Tree---hdu5534(完全背包)
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 题意:有n个节点,让这n个节点形成一棵树,这棵树的种类有很多种,现在告诉n-1个f[i],表示度 ... 
- POJ3260——The Fewest Coins(多重背包+完全背包)
		The Fewest Coins DescriptionFarmer John has gone to town to buy some farm supplies. Being a very eff ... 
- Piggy-Bank(完全背包)
		/* http://acm.hdu.edu.cn/showproblem.php?pid=1114 完全背包问题 再判断背包能否装满 题意: 给出存空钱罐的重量以及装满时的重量 给出每种硬币的面值以及 ... 
- HDU 2546 饭卡(0-1背包)
		http://acm.hdu.edu.cn/showproblem.php?pid=2546 题意: 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金 ... 
- POJ 2184 Cow Exhibition【01背包+负数(经典)】
		POJ-2184 [题意]: 有n头牛,每头牛有自己的聪明值和幽默值,选出几头牛使得选出牛的聪明值总和大于0.幽默值总和大于0,求聪明值和幽默值总和相加最大为多少. [分析]:变种的01背包,可以把幽 ... 
随机推荐
- Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [32,176] milliseco
			有一次,我启动tomcat时,居然花费了33秒.我不理解为什么一个新的tomcat,需要这么久, 网上查找后,找到了一个解决方法. # vim /usr/local/tomcat/bin/catali ... 
- 在jsp中嵌入javascript代码执行对html的影响方式
			1 javascript的作用范围 javascript操作的是html dom树. 它可以用来直接写入html标签:修改html的内容:响应事件:修改html中的图像:修改html的样式等等. 2 ... 
- CENTOS7  修改网卡名称为eth[012...],格式
			具体操作是修改/etc/default/grub文件 在GRUB_CMDLINE_LINUX一行中添加net.ifnames=0 biosdevname=0 保存文件后然后运行 grub2-mkcon ... 
- iview 表单相关
			view表单验证的步骤: 第一步:给 Form 设置属性 rules :rules第二步:同时给需要验证的每个 FormItem 设置属性 prop 指向对应字段即可 prop=”“第三步:注意:Fo ... 
- QT修改应用程序图标
			要准备一个ico的图标,必须是ico格式,切记!! 可以用png或者其他的在线转换:http://www.easyicon.net/covert/ 用记事本 新建文件icon.rc,内容为: IDI_ ... 
- c的详细学习(4)选择结构与循环结构的编程练习
			本节介绍c语言的编程实例. (1)求方程ax^2+bx+0的解: 方程有解有以下几种可能: 1.b^2-4ac=0,方程有两个相等实根. 2.b^2-4ac>0,方程有两个不等实 ... 
- FreeMarker使用后台枚举
			//页面使用枚举全路径访问 model.addAttribute("enums", BeansWrapper.getDefaultInstance().getEnumModels( ... 
- 【leetcode刷题笔记】Merge Intervals
			Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ... 
- 20145229实验三实验报告——敏捷开发与XP实践
			20145229实验三实验报告--敏捷开发与XP实践 实验名称 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 ** 实验步骤**### 敏捷开发与XP 软件工程包括下列领域:软件需求 ... 
- springmvc对象映射个数超过256个
			/** 由于Spring在接受前台传入的List时,就会出现256的IndexOutOfBoundsException异常 设置setAutoGrowCollectionLimit为1024 @par ... 
