题目链接:

pid=2602">HDU 2602 Bone Collector

Bone Collector

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 28903    Accepted Submission(s): 11789

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
 
Author
Teddy
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  1203 2159 2955 2844 1087 
 

经典0/1背包问题。

有N件物品和一个容量为V的背包,第i件物品的体积为v[i],价值为w[i],求解将哪些物品装入背包才干使总价值最大。

这是最基础的背包问题,每种物品仅仅有一件。且仅仅有两种状态:放与不放。

用子问题定义状态:dp[i][v]表示前i件物品恰好放入一个容量为m的包中可获得的最大价值。

状态转移方程:dp[i][m] = max(dp[i-1][m], dp[i-1][m-v[i]]+w[i]);

可转化为一维情况:dp[m] = max(dp[m], dp[m-v[i]]+w[i]);

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; int n, v, dp[1010], value[1010], volume[1010];
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
scanf("%d%d", &n, &v);
for(int i = 1; i <= n; i++)
scanf("%d", &value[i]);
for(int i = 1; i <= n; i++)
scanf("%d", &volume[i]);
memset(dp, 0, sizeof(dp));
for(int i = 1; i <= n; i++)
for(int j = v; j >= volume[i]; j--)
dp[j] = max(dp[j], dp[j-volume[i]]+value[i]);
printf("%d\n", dp[v]);
} return 0;
}

HDU 2602 Bone Collector 0/1背包的更多相关文章

  1. HDOJ(HDU).2602 Bone Collector (DP 01背包)

    HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...

  2. hdu 2602 Bone Collector(01背包)模板

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...

  3. 题解报告:hdu 2602 Bone Collector(01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , in Teddy’s ...

  4. hdu 2602 - Bone Collector(01背包)解题报告

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  5. hdu 2602 Bone Collector(01背包)

    题意:给出包裹的大小v,然后给出n块骨头的价值value和体积volume,求出一路下来包裹可以携带骨头最大价值 思路:01背包 1.二维数组(不常用 #include<iostream> ...

  6. HDU - 2602 Bone Collector(01背包讲解)

    题意:01背包:有N件物品和一个容量为V的背包.每种物品均只有一件.第i件物品的费用是volume[i],价值是value[i],求解将哪些物品装入背包可使价值总和最大. 分析: 1.构造二维数组: ...

  7. HDU 2602 Bone Collector(经典01背包问题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/O ...

  8. HDU 2602 Bone Collector

    http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...

  9. hdu 2602 Bone Collector 背包入门题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 题目分析:0-1背包  注意dp数组的清空, 二维转化为一维后的公式变化 /*Bone Coll ...

随机推荐

  1. 【DB】MYSQL相关细节

    在进行统计API模块测试时候,需要用SQL进行查询,并和API的返回结果进行对比: 而SQL中一些以前用过的细节需要记住: 补充一下show的部分用法: MySQL中有很多的基本命令,show命令也是 ...

  2. JXL基本操作

    一.jxl.jar概述 通过java操作excel表格的工具类库 支持Excel 95-2000的所有版本 生成Excel 2000标准格式 支持字体.数字.日期操作 能够修饰单元格属性 支持图像和图 ...

  3. linux测试工程介绍(Linux Test Project)

    http://ltp.sourceforge.net/ Linux Test Project, 后台很硬,由SGI™ 发起, IBM维护,所以质量有保障. 里面介绍了很多工具,对于一般的基准测试应该是 ...

  4. Linux Shell角本中的条件判断

    1.条件判断: if 使用: if condition; then commands; fi if else 使用: if condition; then commands; else if cond ...

  5. VS2012 No exports were found that match the constraint

    1:打开VS2012新建工程以及打开项目报一下错误提示 2:是由于.NET Framework 4.5 补丁造成的 从:https://www.microsoft.com/zh-CN/download ...

  6. sharepoint 2010 怎样在Ribbon区加入功能button

    继续前面的一篇博客,sharepoint 2010 怎样在列表中加入功能菜单操作项.这次主要是记录下,在Ribbon区域加入功能button.比如加入收藏button.例如以下图所看到的: 1. 还是 ...

  7. Python实现微信刷卡支付(条码支付)MicroPay

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/7686765.html 一:资料阅读 场景介绍:https://pay.weixin.qq.com/wiki/d ...

  8. Hibernate学习笔记二:常用映射配置

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6760895.html 一:单向一对一 常用唯一外键的方法来配置单向一对一关系. 1:实体关系 类A中有类B对象 ...

  9. (二)用控制器controller给模型数据赋初始值

    之前博客,非常easy的就实现了模型数据和页面显示的自己主动绑定.如今我们使用控制器,给模型赋初始值. 假设使用jquery来实现变量赋初值,须要在页面载入完毕后运行$("#target&q ...

  10. springMVC自定义方法属性解析器

    使用场景例子: 用户登陆系统一般会往Session里放置一个VO对象,然后在controller里会来获取用户的userId等信息. 之前的写法是:@SessionAttributes配合@Model ...