hdu 1114 基础完全背包
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
const int maxn=;
const int INF=0x3f3f3f3f;
int n,m,t;
int dp[],w[maxn],v[maxn];
int main()
{
int i,j,k;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
scanf("%d",&t);
while(t--)
{
int a,b;
scanf("%d%d",&a,&b);
int W=b-a;
scanf("%d",&n);
for(i=;i<n;i++) scanf("%d%d",&v[i],&w[i]);
for(i=;i<=W;i++) dp[i]=INF;
dp[]=;
for(i=;i<n;i++)
{
for(j=w[i];j<=W;j++)
{
dp[j]=min(dp[j],dp[j-w[i]]+v[i]);
}
}
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]);
}
}
hdu 1114 基础完全背包的更多相关文章
- HDU 1114 Piggy-Bank(一维背包)
题目地址:HDU 1114 把dp[0]初始化为0,其它的初始化为INF.这样就能保证最后的结果一定是满的,即一定是从0慢慢的加上来的. 代码例如以下: #include <algorithm& ...
- hdu -1114(完全背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 思路:求出存钱罐装全部装满情况下硬币的最小数量,即求出硬币的最小价值.转换为最小背包的问题. # ...
- HDU 1114 Piggy-Bank 完全背包 dp
http://acm.hdu.edu.cn/showproblem.php?pid=1114 完全背包的题目,要求输出最小价值.然后一定要把给出的背包重量全部用完. 就是问一个背包为k的大小,n件物品 ...
- --hdu 1114 Piggy-Bank(完全背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 AC code: #include<bits/stdc++.h> using nam ...
- HDU 1114 Piggy-Bank 全然背包
Piggy-Bank Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit S ...
- HDU 1114 Piggy-Bank(完全背包模板题)
完全背包模板题 #include<cstdio> #include<cstring> #include<algorithm> using namespace std ...
- HDU 1114 【完全背包裸题】
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDU - 1114 Piggy-Bank 完全背包(背包恰好装满)
Piggy-Bank Before ACM can do anything, a budget must be prepared and the necessary financial support ...
- HDU 1114 Piggy-Bank (完全背包)
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
随机推荐
- httpModules与httpHandlers之httpModules(转载)
WapModule.cs:public class WapModule:IHttpModule{ public void Init(HttpApplication context) { ...
- WPF控件模拟双击事件
Action a = () => { i += ; ) { Interval = }; timer.Elapsed += (sender, e) => { timer.Enabled = ...
- IE7下,input元素相对父级元素错位解决办法
原因: 当input仅仅包含父元素,父元素拥有margin属性时,IE7的input就会错误的继承margin属性. 解决办法: 给input元素外面套一个span,label这样的内联元素,这样就会 ...
- 关于笔记本安装双系统windows and linux
ps1.安装完成后,补充下如何设在win7为默认启动系统, 大家也都知道,在linux 运行当软件都是以配置文件来设置参数当,当然grub菜单也不例外, 修改菜单可以进入grub.conf [root ...
- 12个常用的js正则表达式
在这篇文章里,我已经编写了12个超有用的正则表达式,这可是WEB开发人员的最爱哦. 1.在input框中只能输入金额,其实就是只能输入最多有两位小数的数字 //第一种在input输入框限制 <i ...
- getVisibleSize 和 getContentSize 和 getWinSize
getVisibleSize:获得视口(可视区域)的大小,若是DesignResolutionSize跟屏幕尺寸一样大,则getVisibleSize便是getWinSize.getVisibleOr ...
- [ruby on rails] 跟我学之(5)显示所有数据
之前的index页,显示的是hello world,现在将其修改为显示我们在rails console里面录入的数据. 1. 修改action 如之前的章节<[ruby on rails] 跟我 ...
- python代码中使用settings
在具体的Django应用中,通过引入 django.conf.settings 使用配置,例: from django.conf import settings settings.configure( ...
- wget批量下载
wget -i download.txt 这样就会把download.txt里面列出的每个URL都下载下来. wget -c http://the.url.of/incomplete/file 使用断 ...
- MYSQL索引失效的各种情形总结
1) 没有查询条件,或者查询条件没有建立索引 2) 在查询条件上没有使用引导列 3) 查询的数量是大表的大部分,应该是30%以上. 4) 索引本身失效 5) 查询条件使用函数在索引列上,或者对索 ...