HDU2602Bone Collector 简单0-1背包
Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 48618 Accepted Submission(s): 20269
Problem Description
Many years ago , in Teddy’s hometown there was a man who
was called “Bone Collector”. This man like to collect varies of bones , such as
dog’s , cow’s , also he went to the grave …
The bone collector had a big bag with a volume of V ,and along his trip of collecting
there are a lot of bones , obviously , different bone has different value and
different volume, now given the each bone’s value along his trip , can you
calculate out the maximum of the total value the bone collector can get ?
Input
The first line contain a integer T , the number of cases.
Followed by T cases , each case three lines , the first line contain two
integer N , V, (N <= 1000 , V <= 1000 )representing the number of bones
and the volume of his bag. And the second line contain N integers representing
the value of each bone. The third line contain N integers representing the
volume of each bone.
Output
One integer per line representing the maximum of the
total value (this number will be less than 231).
Sample Input
1
5 10
1 2 3 4 5
5 4 3 2 1
Sample Output
14
注意:先输入每个骨头的价值然后输入每个骨头的体积。
状态转移方程:dp[j]=max(dp[j],dp[j-v[i]]+w[i]。
#include <iostream>
#include <string.h> using namespace std;
int N,V;
int dp[];
int w[],v[];
int main()
{
int t;
while(cin>>t){
while(t--){
cin>>N>>V;
for(int i=;i<=N;i++){
cin>>w[i];
}
for(int i=;i<=N;i++){
cin>>v[i];
}
memset(dp,,sizeof(dp));
for(int i=;i<=N;i++){
for(int j=V;j>=v[i];j--){ //j如果小于了v[i]那么v[i]一定无法装入袋子
dp[j]=max(dp[j],dp[j-v[i]]+w[i]);
}
}
cout<<dp[V]<<endl;
}
}
return ;
}
HDU2602Bone Collector 简单0-1背包的更多相关文章
- HDU1712简单的分组背包
HDU1712http://acm.hdu.edu.cn/showproblem.php?pid=1712 简单的分组背包 #include <map> #include <set& ...
- P1417 烹调方案 (0/1背包+贪心)
题目背景 由于你的帮助,火星只遭受了最小的损失.但gw懒得重建家园了,就造了一艘飞船飞向遥远的earth星.不过飞船飞到一半,gw发现了一个很严重的问题:肚子饿了~ gw还是会做饭的,于是拿出了储藏的 ...
- poj1417 带权并查集+0/1背包
题意:有一个岛上住着一些神和魔,并且已知神和魔的数量,现在已知神总是说真话,魔总是说假话,有 n 个询问,问某个神或魔(身份未知),问题是问某个是神还是魔,根据他们的回答,问是否能够确定哪些是神哪些是 ...
- 洛谷 P1064 金明的预算方案 (有依赖的0/1背包)
题目描述 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间金明自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过NN元钱就行”. ...
- POJ 1636 Prison rearrangement DFS+0/1背包
题目链接: id=1636">POJ 1636 Prison rearrangement Prison rearrangement Time Limit: 3000MS Memor ...
- POJ 1745 【0/1 背包】
题目链接:http://poj.org/problem?id=1745 Divisibility Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
- 浙大PAT CCCC L3-001 凑零钱 ( 0/1背包 && 路径记录 )
题目链接 分析 : 就是一个 0/1 背包,但是需要记录具体状态的转移情况 这个可以想象成一个状态转移图,然后实际就是记录路径 将状态看成点然后转移看成边,最后输出字典序最小的路径 这里有一个很巧妙的 ...
- 牛客网 TaoTao要吃鸡 ( 0/1背包变形 )
题意 : 题目链接 分析 : 如果没有 BUG (即 h == 0 的时候)就是一个普通的 0 / 1 背包 需要讨论一下 h != 0 的情况 此时有就相当于有物品是有特权的 而且背包装有特权的物 ...
- HDU 2602 Bone Collector 0/1背包
题目链接:pid=2602">HDU 2602 Bone Collector Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- android应用开发-从设计到实现 2-8 组件与经常使用模式
组件与经常使用模式 前面已经比較全面的介绍了Material Design相关的设计哲学.设计原理和方法论. 这一章開始,我们将看看这些原理是怎样在安卓系统其中得到实践的. 一个应用并非全然从什么都没 ...
- list 组合,模糊查询llist 数据(不走数据库)
@ResponseBody @POST @Path("/megerPerson/{realName}") public ResultEntity partnerL ...
- 淘宝JAVA中间件Diamond
以下是转载自网上资料,但是根据步骤可以搭建出diamond配置中心服务器. 项目中需要用到diamond的理由是, 项目中使用了很多定时任务和异步任务.而且这些定时任务和异步任务都是分布式的安排在多个 ...
- 【Java】Java_11运算符
1.运算符(operator) Java 语言支持如下运算符: 算术运算符: +,-,*,/,%,++ 赋值运算符 = 关系运算符: >,<,>=,<=,==,!= i ...
- Android基于UDP的局域网聊天通信
代码地址如下:http://www.demodashi.com/demo/12057.html 记得把这几点描述好咯:代码实现过程 + 项目文件结构截图 + 演示效果 1. 开发环境 1.1 开发工具 ...
- C#实现的根据日期得到今天是星期几
算法如下: 基姆拉尔森计算公式: W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7 在公式中d表示日期中的日数,m表示月份数,y表示年数.注意:在公式中有 ...
- 单例模式获取JDBC连接
package com.jdbc.test; import java.io.IOException; import java.io.InputStream; import java.sql.Conne ...
- C语言学习笔记(二) 基础知识
数据类型 C语言数据可以分为两大类: 基本类型数据和复合类型数据: 基本类型数据 整数 整型 (int) ——占4字节 短整型(short int) ——占2字节 长整型(long in ...
- weka入门
每天都必须记录自己的一点一滴,不记录下来,过一段时间就会忘记,忘记了就等于没有经历过. 我不能每天这样浑浑噩噩的过下去.我要有计划,有梦想.追求卓越.成就不同. 我今天開始我的学习weka之路.学的时 ...
- 浅谈js中继承的理解和实现
一.前言 java.C#等正统面向对象语言都会提供类似extend之类的处理类的继承的方法,而javascript并没有提供专门的方法用于继承,在javascript中使用继承需要一点技巧.js中实例 ...