Piggy-Bank(完全背包)
/*
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(完全背包)的更多相关文章
- BZOJ 1531: [POI2005]Bank notes( 背包 )
多重背包... ---------------------------------------------------------------------------- #include<bit ...
- ACM Piggy Bank
Problem Description Before ACM can do anything, a budget must be prepared and the necessary financia ...
- ImageNet2017文件下载
ImageNet2017文件下载 文件说明 imagenet_object_localization.tar.gz包含训练集和验证集的图像数据和地面实况,以及测试集的图像数据. 图像注释以PASCAL ...
- ImageNet2017文件介绍及使用
ImageNet2017文件介绍及使用 文件说明 imagenet_object_localization.tar.gz包含训练集和验证集的图像数据和地面实况,以及测试集的图像数据. 图像注释以PAS ...
- Android开发训练之第五章第五节——Resolving Cloud Save Conflicts
Resolving Cloud Save Conflicts IN THIS DOCUMENT Get Notified of Conflicts Handle the Simple Cases De ...
- luogu P3420 [POI2005]SKA-Piggy Banks
题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can either be opened with its correspon ...
- 洛谷 P3420 [POI2005]SKA-Piggy Banks
P3420 [POI2005]SKA-Piggy Banks 题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can eith ...
- [Luogu3420][POI2005]SKA-Piggy Banks
题目描述 Byteazar the Dragon has NNN piggy banks. Each piggy bank can either be opened with its correspo ...
- 深度学习之加载VGG19模型分类识别
主要参考博客: https://blog.csdn.net/u011046017/article/details/80672597#%E8%AE%AD%E7%BB%83%E4%BB%A3%E7%A0% ...
- 【阿菜Writeup】Security Innovation Smart Contract CTF
赛题地址:https://blockchain-ctf.securityinnovation.com/#/dashboard Donation 源码解析 我们只需要用外部账户调用 withdrawDo ...
随机推荐
- Android开发手记(32) 使用摄像头拍照
在Android中,使用摄像头拍照一般有两种方法, 一种是调用系统自带的Camera,另一种是自己写一个摄像的界面. 我们要添加如下权限: <uses-permission android:na ...
- How to customize authentication to my own set of tables in asp.net web api 2?
ssuming your table is called AppUser, convert your own AppUser domain object to IUser(using Microsof ...
- ssh框架配置事务管理器
http://blog.163.com/zsq303288862@126/blog/static/9374596120111182446727/
- 文字排版--删除线(text-decoration:line-through)
如果想在网页上设置删除线怎么办,这个样式在电商网站上常会见到: 上图中的原价上的删除线使用下面代码就可以实现: .oldPrice{text-decoration:line-through;}
- (JavaScript实现)页面无操作倒计时退出
项目前端页面需要实现,页面没人操作进入倒计时,以下为前端代码实现. //设置(倒计时功能)开关 var _mouseActiveListener_flag = true; beforecount:触发 ...
- Java-生成验证码图片(自定义内容,尺寸,路径)
1 package cn.gp.tools; import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; imp ...
- photoshop中rgb与索引模式的区别
RGB: 是色域最宽广的颜色模式它是一种光色模式不难理解 你的显示器 就是根据这个模式来显示图像的同样 我们在自然界中 看到的所有五颜六色的东西都是吸收了不同颜色的光 而得到的所以这一颜色模式 与我 ...
- TaskbarCreated 消息
托盘中的图片就通过注册这个消息来实现,系统和进程通过进程间通信发送这个消息,进程接收他
- linux常用命令(查看某些软件是否已安装)
查看imap是否已安装 rpm -qa | grep imap 以下为未安装的情形: 检查是否已安装sendmail: rpm -qa | grep sendmail 以下为已安装的返回:
- LGDT/LIDT-加载全局/中断描述符表寄存器
将源操作数中的值加载到全局描述符表寄存器 (GDTR) 或中断描述符表寄存器 (IDTR).源操作数指定 6 字节内存位置,它包含全局描述符表 (GDT) 或中断描述符表 (IDT) 的基址(线性地址 ...