/*
http://acm.hdu.edu.cn/showproblem.php?pid=1114
完全背包问题 再判断背包能否装满

题意:
给出存空钱罐的重量以及装满时的重量
给出每种硬币的面值以及重量
求 存钱罐装满时的最小价值。。。若不能装满输出This is impossible

值得注意的两点的是
(1) dp数组的初始化
因为要求的是最小值 所以dp数组赋为最大值但是dp[0]的值为0;
(2) 如何判断背包是否装满

物品个数n
背包容量 C
for(int i=1;i<=n;i++)
for(int j=weight[i];j<=C;j++)
dp[j]=min(dp[j],dp[j-weight[i]+value[i]);
当j=C时 如果dp[j-weight[i]]不是初始值 即:
第i个物品和其他的物品组合能把背包装满
如果dp[j-weight[i]]是初始值 即:反之

*/

include

include

include

using namespace std;
const int inf=0x3f3f3f3f;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int E,F;
scanf("%d%d",&E,&F);
int N;
scanf("%d",&N);
int P[505],M[505],dp[10005];
memset(dp,inf,sizeof(dp));
// for(int i=0;i<=F-E;i++)
// dp[i]=inf;
dp[0]=0;
for(int i=1; i<=N; i++)
scanf("%d%d",&P[i],&M[i]);
for(int i=1; i<=N; i++)
for(int j=M[i]; j<=F-E; j++)
dp[j]=min(dp[j],dp[j-M[i]]+P[i]);
if(dp[F-E]==inf)
printf("This is impossible.\n");
else
printf("The minimum amount of money in the piggy-bank is %d.\n",dp[F-E]);
}
return 0;
}

Piggy-Bank(完全背包)的更多相关文章

  1. BZOJ 1531: [POI2005]Bank notes( 背包 )

    多重背包... ---------------------------------------------------------------------------- #include<bit ...

  2. ACM Piggy Bank

    Problem Description Before ACM can do anything, a budget must be prepared and the necessary financia ...

  3. ImageNet2017文件下载

    ImageNet2017文件下载 文件说明 imagenet_object_localization.tar.gz包含训练集和验证集的图像数据和地面实况,以及测试集的图像数据. 图像注释以PASCAL ...

  4. ImageNet2017文件介绍及使用

    ImageNet2017文件介绍及使用 文件说明 imagenet_object_localization.tar.gz包含训练集和验证集的图像数据和地面实况,以及测试集的图像数据. 图像注释以PAS ...

  5. Android开发训练之第五章第五节——Resolving Cloud Save Conflicts

    Resolving Cloud Save Conflicts IN THIS DOCUMENT Get Notified of Conflicts Handle the Simple Cases De ...

  6. luogu P3420 [POI2005]SKA-Piggy Banks

    题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can either be opened with its correspon ...

  7. 洛谷 P3420 [POI2005]SKA-Piggy Banks

    P3420 [POI2005]SKA-Piggy Banks 题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can eith ...

  8. [Luogu3420][POI2005]SKA-Piggy Banks

    题目描述 Byteazar the Dragon has NNN piggy banks. Each piggy bank can either be opened with its correspo ...

  9. 深度学习之加载VGG19模型分类识别

    主要参考博客: https://blog.csdn.net/u011046017/article/details/80672597#%E8%AE%AD%E7%BB%83%E4%BB%A3%E7%A0% ...

  10. 【阿菜Writeup】Security Innovation Smart Contract CTF

    赛题地址:https://blockchain-ctf.securityinnovation.com/#/dashboard Donation 源码解析 我们只需要用外部账户调用 withdrawDo ...

随机推荐

  1. ASP.NET MVC5框架揭秘 学习笔记01

    1.自治视图 在早期(作者也没说明是多早,自己猜吧),我们倾向于将所有与UI相关的操作糅合在一起(现在我身边还有很多人这样做),这些操作包括UI界面的呈现. 用户交互操作的捕捉与响应(UI处理逻辑). ...

  2. c# 连接oracle 读取数据

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  3. mysql 远程访问 配置

    sudo vi /etc/mysql/my.cnf 找到bind-address = 127.0.0.1 注释掉这行:#bind-address = 127.0.0.1 或者改为: bind-addr ...

  4. .net RAW(16)与GUID互相转换

    .net 1.raw转guidnew guid(byte[] id);2.guid转rawGuid result;string ids = BitConverter.ToString(result.T ...

  5. Javascript基础(2)

    开始更咯~~~嘻嘻. ---------------------------------------------------------------------------------- 异常捕获:即 ...

  6. express 安装与卸载

    卸载: npm uninstall -g express安装指定版本: npm install -g express@3.5.0查看版本: express -V注意express -V中的V要大写,不 ...

  7. java_设计模式_命令模式_Command Pattern(2016-08-09)

    理解还不到位,先窜出来.等过一阵子再看,再理解. 定义:将一个请求封装成一个对象,从而让你使用不同的请求把客户端参数化,对请求排队或者记录请求日志,可以提供命令的撤销和恢复功能. 类型:行为类模式 类 ...

  8. 初试ubuntu14.4问题集锦

    接触Linux系统也好长时间了,但每次都是浅尝则止.前几天突发兴趣,想认真地学习一下这个名扬天下的稳定的操作系统.于是试着装了一下炒作的最凶的Ubuntu. 安装的Ubuntu系统版本为14.04. ...

  9. windows7 64 位 mysql 5.6.12 安装

    1.修改 my-default.ini 改名为 my.ini 内容修改为 [mysqld] loose-default-character-set = utf8    basedir = D:/mys ...

  10. eclipse中show whitespace characters显示代码空格,TAB,回车 导致代码乱恶心

    Eclipse中show whitespace characters显示回车.空格符. 取消此功能的第二种方式: