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. [状态压缩,折半搜索] 2019牛客暑期多校训练营(第九场)Knapsack Cryptosystem

    链接:https://ac.nowcoder.com/acm/contest/889/D来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言52428 ...

  2. Spring05——Spring 如何实现事务管理

    在此之前,我们已经了解了 Spring 相关的基础知识,今天将为给位带来,有关 Spring 事务代理的相关知识.关注我的公众号「Java面典」,每天 10:24 和你一起了解更多 Java 相关知识 ...

  3. 【笔记3-26】Python语言基础

    编译型语言和解释型语言 编译型语言 C 先编译 解释型语言 Python 边执行边编译 Python的介绍 吉多·范罗苏姆 1991 解释型语言 Life is short you need Pyth ...

  4. 深度强化学习(DRL)专栏(一)

    目录: 1. 引言 专栏知识结构 从AlphaGo看深度强化学习 2. 强化学习基础知识 强化学习问题 马尔科夫决策过程 最优价值函数和贝尔曼方程 3. 有模型的强化学习方法 价值迭代 策略迭代 4. ...

  5. SVN钩子HOOK设置自动备份,服务本地可以看到所有更新内容。

    可以实现SVN本机备份.或者其他备份.关键是可以保持有一份最新的SVN文件可以查看. 实现SVN与WEB同步,可以CO一个出来,也可以直接用自动更新web目录的方法,我们要在svn版本库中配置钩子来实 ...

  6. 使用FME将CAD中块参照数据转换为shp数据

    暴露出需要导出的字段值,首先在数据查看器中看看CAD中各个图层分别有哪些隐含的字段. CAD快参照中含有多个部分,需要将点按照原始编码聚合成一个点. 属性字段创建,并按照属性字段一一对应CAD中的字段 ...

  7. 线程 -- ThreadLocal

    1,ThreadLocal 不是“本地线程”的意思,而是Thread 的局部变量.每个使用该变量的线程提供独立的变量副本,所以每一个线程都可以独立地改变自己的副本,而不会影响其它线程所对应的副本 2, ...

  8. JavaScript 异步、栈、事件循环、任务队列

    概览 我们经常会听到引擎和runtime,它们的区别是什么呢? 引擎:解释并编译代码,让它变成能交给机器运行的代码(runnable commands). runtime:就是运行环境,它提供一些对外 ...

  9. elasticsearch异常问题 discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

    本文使用环境  centos7.x   elasticsearch7.6.2   JDK1.8 错误:文件权限不足      [1]: max file descriptors [4096] for ...

  10. JS 剑指Offer(三) 替换字符串中的空格

    请实现一个函数,把字符串 s 中的每个空格替换成"%20". 实现这个函数的方法很简单,在JS中可以直接应用正则表达式,代码如下 直接将全局中的space换成%20,一行代码搞定 ...