题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/N

题目:

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 2 31).
 

Sample Input

1
5  10
1  2  3  4  5
5  4  3  2  1
 

Sample Output

14

分析:

将前i件物品放入容量为j的背包中”这个子问题,若只考虑第i件物品的策略(放或不放),那么

就可以转化为一个只牵扯前i-1件物品的问题。如果不放第i件物品,那么问题就转化为“前i-1件

物品放入容量为j的背包中”,价值为f[i-1][j];如果放第i件物品,那么问题就转化为“前i-1件物品放

入剩下的容量为j-v[i]的背包中”,此时能获得的最大价值就是f[i-1][j-v[i]]再加上通过放入第i件物品获得的价值m[i] .

#include<iostream>
#include<cstring>
using namespace std;
int m[],v[];
int f[][];
int max(int a,int b)
{
if(a>b) return a;
else return b;
}
int main()
{
int t,n,i,j,M;
cin>>t;
while(t--)
{
cin>>n>>M;
for(i=;i<=n;i++)
cin>>m[i];
for(i=;i<=n;i++)
cin>>v[i];
for(i=;i<=n;i++)
for(j=;j<=M;j++)
{
f[i][j]=(i==?:f[i-][j]);
if(j>=v[i])
f[i][j]=max(f[i][j],f[i-][j-v[i]]+m[i]);
}
cout<<f[n][M]<<endl;
}
return ;
}

Bone Collector(01背包)的更多相关文章

  1. Bone Collector(01背包+记忆化搜索)

    Bone Collector Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

  2. HDU 2602 Bone Collector(01背包裸题)

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

  3. hdu2602 Bone Collector 01背包

    Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like ...

  4. HDU 2602 - Bone Collector - [01背包模板题]

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

  5. [原]hdu2602 Bone Collector (01背包)

    本文出自:http://blog.csdn.net/svitter 题意:典型到不能再典型的01背包.给了我一遍AC的快感. //=================================== ...

  6. hdu2602 Bone Collector (01背包)

    本文来源于:http://blog.csdn.net/svitter 题意:典型到不能再典型的01背包.给了我一遍AC的快感. //================================== ...

  7. HDU 2602 Bone Collector --01背包

    这种01背包的裸题,本来是不想写解题报告的.但是鉴于还没写过背包的解题报告.于是来一发. 这个真的是裸的01背包. 代码: #include <iostream> #include < ...

  8. ACM HDU Bone Collector 01背包

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 这是做的第一道01背包的题目.题目的大意是有n个物品,体积为v的背包.不断的放入物品,当然物品有 ...

  9. 解题报告:hdu2602 Bone collector 01背包模板

    2017-09-03 15:42:20 writer:pprp 01背包裸题,直接用一维阵列的做法就可以了 /* @theme: 01 背包问题 - 一维阵列 hdu 2602 @writer:ppr ...

  10. HDU 2602 Bone Collector (01背包DP)

    题意:给定一个体积,和一些物品的价值和体积,问你最大的价值. 析:最基础的01背包,dp[i] 表示体积 i 时最大价值. 代码如下: #pragma comment(linker, "/S ...

随机推荐

  1. 基于MATLAB的adaboost级联形式的人脸检测实现

    很早之前就做过一些关于人脸检测和目标检测的课题,一直都没有好好总结出来,趁着这个机会,写个总结,希望所写的内容能给研究同类问题的博友一些见解和启发!!博客里面涉及的公式太繁琐了,直接截图了. 转载请注 ...

  2. 在Salesforce中进行Report和Dashboard的配置

    用Report和Dashboard去图形化比较不同Object的信息是一个十分普遍的需求,当然我们可以完全用Visual Page和Classes去自定义对应的Report和Dashboard的功能. ...

  3. HTML的格式、内容容器、表格标签

    HTML(Hyper Text Markup Language,超文本标记语言)超指的是超链接. <html>    --开始标签 <head> 网页上的控制信息 <ti ...

  4. host_network_interfaces_slow_mode_thresholds

    CDH报集群异常: host_network_interfaces_slow_mode_thresholds 警告置为从不-- 主要是我没有查到发生这种情况的原因是什么--

  5. Web Tours自带示例网站无法打开的解决方案

    问题现象: LoadRunner自带的测试样品,旅行社机票预订系统HP Web Tours以下简称为Web Tours. 1.LoadRunner程序的Sample目录下无Web和Web Tours服 ...

  6. LoadRunner脚本实例来验证参数化的取值

    LoadRunner脚本实例来验证参数化的取值 SINM {3]!G0问题提出:  主要想试验下,在Controller中,多个用户,多次迭代中参数的取值.51Testing软件测试网(['H5f,d ...

  7. a与a:link、a:visited、a:hover、a:active

    原文地址http://www.cnblogs.com/exmyth/p/3226654.html a与a:link.a:visited.a:hover.a:active   起因: a与a:link的 ...

  8. DSP using MATlAB 示例Example2.10

    上代码 % noise sequence 1 x = [3, 11, 7, 0, -1, 4, 2]; nx = [-3:3]; % given signal x(n) [y,ny] = sigshi ...

  9. css3 -- 伪类与伪元素

    伪类: 1.结构伪类 A:E : first-child{} E : nth-*(n){} E : first-*(even){}  E : first-*(odd){} B:nth-child 是根 ...

  10. iOS 安装Cocoapods以及安装第三方库的操作流程

    安装cocoapods的流程: 1.打开终端,输入:  sudo gem update —system 2.输入密码,稍等 3.gem sources --remove https://rubygem ...