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. Javascript之盒子拖拽(跟随鼠标、边界限定、轨迹回放)

    本文通过拖拽案例,实现"跟随鼠标.边界限定.轨迹回放"三大效果: 完整代码中有详尽注释,故不再进行细致讲解: 对于案例中需要注意的重点或易错点问题,会总结在最后. 效果图(仅演示左 ...

  2. 你真的理解 if __name__ == '__main__' 的作用么?

    https://blog.csdn.net/Amberdreams/article/details/88382993

  3. Jocke的IOT之路--raspberrypi更换国内镜像

    一.编辑sources.list文件 sudo nano /etc/apt/sources.list 使用#将文件内容全部注释调,更改位 deb http://mirrors.tuna.tsinghu ...

  4. Building Applications with Force.com and VisualForce(Dev401)(十一):Designing Applications for Multiple Users: Proseving Data Quality

    Dev401-012:Proseving Data Quality Universal Containers Scenario1.Universal Containers(UC) wants to e ...

  5. 4D

    GIS行业通常将GIS常用的数据产品概括为“4D”,即:DOM(数字正射影像图).DEM(数字高程模型).DLG(数字线划地图).DRG(数字栅格地图).以及复合模式派生数据组成. DOM:数字正射影 ...

  6. ajax实现图片上传与进度条

    这里使用的是bootstract的一个插件来实现 详情请查看文档中的进度条 https://v3.bootcss.com/components/ 引入必要的文件 <link href=" ...

  7. 已知IP地址和子网掩码求出网络地址、广播地址、地址范围和主机数(转载https://blog.csdn.net/qq_39026548/article/details/78959089)

    假设IP地址为128.11.67.31,子网掩码是255.255.240.0.请算出网络地址.广播地址.地址范围.主机数.方法:将IP地址和子网掩码转化成二进制形式,然后进行后续操作. IP地址和子网 ...

  8. iOS 图片的解压缩

    一.图片加载的工作流 概括来说,从磁盘中加载一张图片,并将它显示到屏幕上,中间的主要工作流如下: 假设我们使用 +imageWithContentsOfFile: 方法从磁盘中加载一张图片,此时的图片 ...

  9. ThreadAbortException是可以传递的

    今天在写线程Aborted代码时,发现嵌套的try catch中的ThreadAbortException错误是可以从内部传递到外部的,想想这也是必然的,在内部该线程已经中断了,外部必然是中断了,再仔 ...

  10. k8s 集群管理和微服务 适合做啥

    k8s 集群管理和微服务 适合做啥 都知道k8s是集群 适合微服务 有很多教程 但你可以先了解他能干啥 traefix 是负载均衡工具 k8s 适合部署无状态依赖的微服务 可以按需求开启多个微服务 管 ...