Bone Collector

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
 
——————————————————————————————————————————————————————————————————————
最最最最最最最经典的01背包问题,告诉你物品数量和背包容量及各件物品的质量和价值,求最大价值
我们来考虑第i件物品的决策情况
若容量够可以取,则考虑取了之后最大价值和不取的最大价值何者大,即dp[i][j]=max(dp[i][j-1],dp[i-weight[j]][j-1]+val[j]);

若容量不够不能取,则dp[i][j]=dp[i][j-1];

代码入下:


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int dp[1005][1005];
int main()
{
int weight[1005],val[1005],sum,n,o;
while(~scanf("%d",&o))
{
while(o--)
{
scanf(" %d %d",&n,&sum);
for(int i=1;i<=n;i++)
scanf("%d",&val[i]);
for(int i=1;i<=n;i++)
scanf("%d",&weight[i]);
memset(dp,0,sizeof(dp));
for(int i=0;i<=sum;i++)
for(int j=1;j<=n;j++)
{
if(dp[i][j]+weight[j]<=i)
dp[i][j]=max(dp[i][j-1],dp[i-weight[j]][j-1]+val[j]);
else
dp[i][j]=dp[i][j-1];
}
printf("%d\n",dp[sum][n]); }
}
return 0;
}



hdu2602 Bone Collector(01背包) 2016-05-24 15:37 57人阅读 评论(0) 收藏的更多相关文章

  1. hdu2602 Bone Collector 01背包

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

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

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

  3. hdu2602 Bone Collector (01背包)

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

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

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

  5. NYOJ-289 苹果 289 AC(01背包) 分类: NYOJ 2014-01-01 21:30 178人阅读 评论(0) 收藏

    #include<stdio.h> #include<string.h> #define max(x,y) x>y?x:y struct apple { int c; i ...

  6. HDU-2602 Bone Collector——01背包

    首先输入一个数字代表有n个样例 接下来的三行 第一行输入n  和  v,代表n块骨头,背包体积容量为v. 第二行输入n块骨头的价值 第三行输入n块骨头的体积 问可获得最大的价值为多少 核心:关键在于d ...

  7. hdu1171 Big Event in HDU(01背包) 2016-05-28 16:32 75人阅读 评论(0) 收藏

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  8. 【C#小知识】C#中一些易混淆概念总结(二)--------构造函数,this关键字,部分类,枚举 分类: C# 2014-02-03 01:24 1576人阅读 评论(0) 收藏

    目录: [C#小知识]C#中一些易混淆概念总结--------数据类型存储位置,方法调用,out和ref参数的使用 继上篇对一些C#概念问题进行细节的剖析以后,收获颇多.以前,读书的时候,一句话一掠而 ...

  9. Hardwood Species 分类: POJ 树 2015-08-05 16:24 2人阅读 评论(0) 收藏

    Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 20619 Accepted: 8083 De ...

随机推荐

  1. kegg富集分析之:KEGGREST包(9大功能)

    这个包依赖极有可能是这个:https://www.kegg.jp/kegg/docs/keggapi.html ,如果可以看懂会很好理解 由于KEGG数据库分享数据的策略改变,因此KEGG.db包不在 ...

  2. IntelliJ IDEA project module

    在IDEA 创建一个project,目录结构是这样的:在project下创建一个module之后目录结构是这样的: 简单的概括如下: IntelliJ系中的 Project  相当于Eclipse系中 ...

  3. function方法控制是否隐藏部分内容

    $(document).ready(function() { $('input[type=radio][name=IE]').change(function() { if (this.value == ...

  4. 元素的定位tag_name,link_text,class_name

    tag_name 就是根据HTML的标签的名称来定位的: 案例:打开我要自学网,会有用户名和密码的输入框 例如:拿51zxw.net为例 from time import sleep #加载浏览器驱动 ...

  5. SharePoint 2010 外部数据类型

    需求描述: 在sharepoint 2010有时需要访问外部的数据(如sql数据库). 参考文章: 外部内容类型 Business Connectivity Services ECT外部内容类型 Se ...

  6. 基于Woodstox的StAX 2 (Streaming API for XML)解析XML

    StAX (Streaming API for XML)面向流的拉式解析XML,速度快.占用资源少,非常合适处理大数据量的xml文件. 详细教程和说明可以参见以下几篇文章: 使用 StAX 解析 XM ...

  7. np.random.random()系列函数

    1.np.random.random()函数参数 np.random.random((1000, 20)) 上面这个就代表生成1000行 20列的浮点数,浮点数都是从0-1中随机. 2.numpy.r ...

  8. C# 发送电子邮件(含附件)用到的类 system.web.mail

    主要是用到了System.Web.Mail命名空间,用到了此空间的三个类,分别是: ●MailMessage类,用于构造电子邮件●MailAttachment类,用于构造电子邮件附件●SmtpMail ...

  9. Thread(线程)和ThreadPool(线程池) Thread回调与返回值

    Thread(线程) Thread开启线程:接收一个参数 TestClass tc = new TestClass(); //没有返回值,有一个object类型的参数的委托:两种写法. Paramet ...

  10. JavaScript 中的 NaN 和 isNaN

    1.NaN NaN 即 Not a Number , 不是一个数字.那么 NaN 到底是什么呢? 在 JavaScript 中,整数和浮点数都统称为 Number 类型 .除此之外,Number 类型 ...