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开发框架-------PowerFramework使用心得(四)数据库管理DBFarmer
DBFarmer是PowerFramework数据库管理工具的集合. 可以进行对象的存储,添加了setter和getter的参数会被收录到数据库中,每个参数作为一个项,int类型的id或_id会被作为 ...
- SQL SERVER 查看死锁的存储过程
end
- oracle-snapshot too old 示例
一.快照太老例子: 1.创建一个很小的undo表空间,并且不自动扩展. create undo tablespace undo_small datafile '/u01/app/oracl ...
- 解决ld: warning: directory not found for option警告
去掉警告的办法如下: 1选择工程, 编译的 (targets) 2选择 Build Settings 菜单 3查找 Library Search Paths 和 Framework Search Pa ...
- EBS成本核算方法
业务背景 成本核算方法,对应EBS系统中的成本方法,有四种: 1.标准成本 2.平均成本 平均成本又分为永续平均成本,即 Average Cost 期间平均成本,按照期间(自然月)来计算的平均成本 F ...
- servlet的doPost 和doGet和web文件结构
doPost和doGet分别由 tomcat自己来决定调用post 还是get 方式查询 get:url有少量的参数信息,一般用到查询那里 (像百度.. post一般用来提交大文件数据(二进制数据 d ...
- jQuery实现公告文字左右滚动的代码。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- js编译和执行顺序
JS是一段一段执行的(以<script>标签来分割),执行每一段之前,都有一个“预编译”,预编译干的活是:声明所有var变量(初始为undefined),解析定义式函数语句. 还有个关于 ...
- ubuntu 安装 open in teminal
sudo apt-get install nautilus-open-terminalnautilus -q
- Flask 富文本编辑器
XHEditor http://segmentfault.com/blog/digwtx/1190000002439076 CKeditor http://segmentfault.com/blog/ ...