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 ? 

InputThe 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.OutputOne 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
一个很简单的背包问题,但是用dfs记忆化搜索也可做,并且复杂度相同
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1E3+;
int n,m;
ll v[N];
ll w[N];
ll dp[N][N];
ll dfs(int x,int y){
ll ans=;
if(x<=) return ;
if(dp[x][y]) return dp[x][y];
if(w[x]>y) ans=dfs(x+,y);
else {
ans=max(dfs(x+,y),dfs(x+,y-w[x])+v[x]);
}
return dp[x][y]=ans;
}
int main(){
int t;
cin>>t;
while(t--){
cin>>n>>m;
for(int i=;i<=n;i++){
cin>>v[i];
}
for(int j=;j<=n;j++)
cin>>w[j];
memset(dp,,sizeof(dp));
cout<<dfs(,m)<<endl;
} return ;
}

写dfs的时候一定要清楚它的返回值的意义。

F - Bone Collector的更多相关文章

  1. Bone Collector(01背包)

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

  2. HDU 2602 Bone Collector

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

  3. Bone Collector(ZeroOnebag)

    Bone Collector Problem Description Many years ago , in Teddy’s hometown there was a man who was call ...

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

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

  5. bone collector hdu 01背包问题

    Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...

  6. Hdoj 2602.Bone Collector 题解

    Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bone C ...

  7. hdu2602 Bone Collector 01背包

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

  8. Bone Collector(hdoj--2602--01背包)

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

  9. HDU2602 Bone Collector(01背包)

    HDU2602 Bone Collector 01背包模板题 #include<stdio.h> #include<math.h> #include<string.h&g ...

随机推荐

  1. 用java分组查elasticsearch

    哎,编程路漫漫,一坑又一坑,爬完还会掉,何时是尽头! 今朝有酒今朝醉,程序不对不敢睡! 还是接口昂,今天还是接口有问题,我是很菜,很笨,但是我还是要努力!! 正文: 接口需求是这样的,根据车型查询在线 ...

  2. 搭建生产级的Netty项目

    Netty是Trustin Lee在2004年开发的一款高性能的网络应用程序框架.相比于JDK自带的NIO,Netty做了相当多的增强,且隔离了jdk nio的实现细节,API也比较友好,还支持流量整 ...

  3. css网页重置样式表(多版本)

    Eric reset.css html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, ...

  4. 在dev分支上修改了文件,但是并没有执行git add. 和git commit命令,然后切换到master分支,仍然能看到dev分支的改动现象

    当我们创建一个新的分支dev,并且在新分支上修改了原文件,在我们没有提交到仓库的前提下,将分支再切换到master分支上,执行git status ,可以看到dev操作的状态: (1)因为未add的内 ...

  5. python之面向对象三大特性: 继承(单继承)

    什么是继承 专业角度: B 继承 A类, B就叫做A的子类,派生类, A叫做B的父类,基类,超类. B类以及B类的对象使用A类的所有的属性以及方法. 字面意思: 继承就是继承父母所有的资产 class ...

  6. TensorFlow 实战卷积神经网络之 LeNet

    欢迎大家关注我们的网站和系列教程:http://www.tensorflownews.com/,学习更多的机器学习.深度学习的知识! LeNet 项目简介 1994 年深度学习三巨头之一的 Yan L ...

  7. redis吊锤面试官,这篇足够了!

    原理篇 redis 时单线程的为什么还能那么快? 数据都在内存中,运算都是内存级别的运算. redis既然是单线程的为什么能处理那么多的并发数? 多路复用,操作系统时间轮训epoll 函数作为选择器, ...

  8. [vijos1048]送给圣诞夜的贺卡<DFS剪枝>

    题目链接:https://www.vijos.org/p/1048 很多人一看就想出了思路,不就是一个裸的dfs蛮...但是..在n<=50的情况下,朴素会直接tle..... 然后我就开始剪枝 ...

  9. MATLAB 大数相乘溢出显示

    解一道面试题——华为社招现场面试1:请使用代码计算1234567891011121314151617181920*2019181716151413121110987654321 . 乘积是逐位相乘,也 ...

  10. [斯坦福大学2014机器学习教程笔记]第五章-控制语句:for,while,if语句

    在本节中,我们将学习如何为Octave程序写控制语句. 首先,我们先学习如何使用for循环.我们将v设为一个10行1列的零向量. 接着,我们写一个for循环,让i等于1到10.写出来就是for i = ...