/*
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. Adb工具常用操作(一)

    一.启动或关闭server 1.3  Android SDK中的常用命令行工具 在<Android SDK安装目录>\tools目录中带了很多命令行工具.虽然一般的开发人员并不需要完全掌握 ...

  2. List<T>取交集、差集、并集

    1.  取交集 (A和B都有) List A : { 1 , 2 , 3 , 5 , 9 }List B : { 4 , 3 , 9 }var intersectedList = list1.Inte ...

  3. 最简单的基于FFmpeg的移动端例子:IOS 推流器

    转至:http://blog.csdn.net/leixiaohua1020/article/details/47072519   ================================== ...

  4. 07ADO.Net

    1.ADO.Net简介 代码示例: using (MySqlConnection conn = new MySqlConnection("Server=localhost;Database= ...

  5. 在万网虚拟主机上部署MVC5

    参考 要想部署mvc,需要把一些mvc用到的全局程序集改为本地部署,通过N次试验,终于搞定. 特写个备忘录,免得以后忘了. 首先更改web.config,在里面加上 <system.web> ...

  6. C蛮的全栈之路-node篇(一) 环境布置

    目录 C蛮的全栈之路-序章 技术栈选择与全栈工程师C蛮的全栈之路-node篇(一) 环境布置C蛮的全栈之路-node篇(二) 实战一:自动发博客 ---------------- 我是分割线 ---- ...

  7. js 支持的原始数据类型

    原始数据类型: 数值型: 1.十进制数 <script> var a =12; a = -12 a = 12.4 a =.23e2 //=>23 a = 2e3 //=>200 ...

  8. php判断手机移动设备访问

    <?php function isMobile() { // 如果有HTTP_X_WAP_PROFILE则一定是移动设备 if (isset ($_SERVER['HTTP_X_WAP_PROF ...

  9. Js冒泡事件和捕获事件

    js中冒泡事件和捕获事件: 冒泡事件:冒泡事件是从里向外,即是从被绑定元素开始一直向外到达页面的所有祖先元素都会被触发,这 一过程被称为事件冒泡.这个事件从原始元素开始一直冒泡到DOM树的最上层 捕获 ...

  10. Day12 线程池、RabbitMQ和SQLAlchemy

    1.with实现上下文管理 #!/usr/bin/env python# -*- coding: utf-8 -*-# Author: wanghuafeng #with实现上下文管理import c ...