题目链接:

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. 查看oracle的sql语句历史记录和锁表的情况

    查看oracle的sql语句历史记录和锁表的情况 (2012-01-04 20:59:59) 转载▼ 标签: 杂谈 分类: database 查询sql的历史记录 select * from v$sq ...

  2. 解析Linux操作系统文件目录

    解析Linux操作系统文件目录 随着Linux的不断发展,越来越多的人开始使用Linux,对于那些刚刚接触的人来说,恐怕最先感到困惑的就是那些“不明不白”的目录了.如果想熟练使用Linux,让Linu ...

  3. iOS编程(双语版) - 视图 - 基本概念

    1. 什么是视图? 视图显示为手机上的一块矩形区域,管理该区域的所有屏幕显示,它是UIView或者UIView的子类. 视图既可以从xib生成,也可以用代码生成. 2. 窗口 窗口是UIWindow或 ...

  4. Cocon90.Db调用方法

    Cocon90.DB 使用说明 开源库:https://github.com/Cocon90/Cocon90.Db Sqlite位置:https://www.nuget.org/packages/Co ...

  5. HttpClient Restful Post 请求

    public static void main(String[] args) { SbVo sb = new SbVo(); sb.setBusiness("SB"); sb.se ...

  6. Maven进行Mahout编程,使其兼容Hadoop2.2.0环境运行 (转)

    http://blog.csdn.net/u010967382/article/details/39209329 http://blog.csdn.net/fansy1990/article/deta ...

  7. 算法笔记_200:第三届蓝桥杯软件类决赛真题(C语言本科)

    目录 1 星期几 2 数据压缩 3 拼音字母 4 DNA比对 5 方块填数   前言:以下代码部分仅供参考,若有不当之处,还望路过同学指出哦~ 1 星期几 1949年的国庆节(10月1日)是星期六. ...

  8. 【麦子学院】Linux cmd命令大全

    pwd :print working directory. 打印工作文件夹即当前文件夹. cd :change directory.切换文件夹. /是linux的根文件夹.eg. cd/home ls ...

  9. springMVC加载远程freemarker模板文件

    在一个大网站里,有很多子域名,也就是有很多子系统,这些子系统由不同的团队负责,对整个网站的风格的风格至少得要是一致的(最基本的页头.页尾必须一致),这个时候得提供一份统一的页头.页尾以及公共的JS.c ...

  10. java第二节 基本数据类型

    class Lesson2 { public static void main(String[] args) { //----------------------------------- //@Da ...