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. 迷你MVVM框架 avalonjs 学习教程22、avalon性能大揭密

    avalon之所以能在页面处理1W个绑定(angular对应的数字是2000),出于两个重要设计--基于事件驱动的双向绑定链及智能CG回收机制. avalon的双向绑定链是通过Object.defin ...

  2. Python内置类型性能分析

    Python内置类型性能分析 timeit模块 timeit模块可以用来测试一小段Python代码的执行速度. class timeit.Timer(stmt='pass', setup='pass' ...

  3. 2021工厂增加2322仓位需求,参与FP分析

    在以下语句取消2322工厂即可 INSERT INTO STG.SAP_MARD(MATNR, WERKS, LGORT, LABST, UMLME, INSME, EINME, SPEME, LGO ...

  4. IIS中的MIME类型设置

    https://www.cnblogs.com/David-Young/p/5323949.html

  5. EasyUI_tabs和layout布局, 点击链接打开标签, 重复点击选中标签

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  6. Python3 List list()方法

    Python3 List list()方法  Python3 列表 描述 list() 方法用于将元组或字符串转换为列表. 注:元组与列表是非常类似的,区别在于元组的元素值不能修改,元组是放在括号中, ...

  7. iOS下JS与OC互相调用(七)--Cordova 环境搭建

    Cordova大家可能比较陌生,但肯定听过 PhoneGap ,Cordova 就是 PhoneGap 被 Adobe 收购后所改的名字.它是一个可以让 JS 与原生代码互相通信的一个库,并且提供了一 ...

  8. collections系列之OrderedDict【有序字典】与DefaultDict【默认字典】

    今天来向大家介绍一下collections系列中的OrderedDict和DefaultDict,这两种类均是通过collections来创建的,均是对dict字典加工,所有都继承了dict字典的方法 ...

  9. php5.3 延迟静态绑定 static关键字

    //传统模式 --这段代码能很好工作,但大量的重复代码很烦人,不想为每个DomainObject子类都创建这段相同代码吧? /* abstract class DomainObject{} class ...

  10. ubuntu 安装 google Gtest

    1.安装源代码 在ubuntu的桌面上,右键选择打开终端,在终端中输入如下命令: $ sudo apt-get install libgtest-dev 下载源码后,apt将会在目录/usr/src/ ...