F - Bone Collector
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的更多相关文章
- Bone Collector(01背包)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/N 题目: Description Many year ...
- HDU 2602 Bone Collector
http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...
- Bone Collector(ZeroOnebag)
Bone Collector Problem Description Many years ago , in Teddy’s hometown there was a man who was call ...
- Bone Collector(01背包+记忆化搜索)
Bone Collector Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- bone collector hdu 01背包问题
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...
- Hdoj 2602.Bone Collector 题解
Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bone C ...
- hdu2602 Bone Collector 01背包
Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like ...
- Bone Collector(hdoj--2602--01背包)
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU2602 Bone Collector(01背包)
HDU2602 Bone Collector 01背包模板题 #include<stdio.h> #include<math.h> #include<string.h&g ...
随机推荐
- C 2013笔试题
1.把整数分解成素数 如90=2*3*3*5 [见2015年] 方法一: int main() { int n, i=2; printf("\nInput:"); scanf(&q ...
- 【Unity游戏开发】跟着马三一起魔改LitJson
一.引子 在游戏开发中,我们少不了和数据打交道,数据的存储格式可谓是百花齐放,xml.json.csv.bin等等应有尽有.在这其中Json以其小巧轻便.可读性强.兼容性好等优点受到广大程序员的喜爱. ...
- centos7 LVM扩容案例
测试数据 cd / && dd if=/dev/zero of=file bs=1M count=10000 将磁盘变大的测试命令. 生产环境不要用. 这只是用于测试扩容后的效果 LV ...
- 《JavaScript 模式》读书笔记(4)— 函数5
这一篇是函数部分的最后一篇.我们来聊聊Curry化. 十.Curry 这部分我们主要讨论Curry化和部分函数应用的内容.但是在深入讨论之前,我们需要先了解一下函数应用的含义. 函数应用 在一些纯粹的 ...
- MySQL笔记(9)-- 各种锁及实现
一.背景 MySQL有两种类型的锁:lock(锁)和latch(闩锁): 类型 lock latch 对象 事务 线程 保护 数据库内容 内存数据结构 持续时间 整个事务 临界资源 模式 行锁.表锁. ...
- 数据科学中需要知道的5个关于奇异值分解(SVD)的应用
介绍 "Another day has passed, and I still haven't used y = mx + b." 这听起来是不是很熟悉?我经常听到我大学的熟人抱怨 ...
- 万字综述,核心开发者全面解读PyTorch内部机制
斯坦福大学博士生与 Facebook 人工智能研究所研究工程师 Edward Z. Yang 是 PyTorch 开源项目的核心开发者之一.他在 5 月 14 日的 PyTorch 纽约聚会上做了一个 ...
- SpringCloud服务的注册发现--------Eureka
1,什么叫做服务的注册与发现 服务的注册与发现基于注册中心,注册中心本身是一个服务,也相当于一个载体,其他服务的注册需要注册到这个注册中心上. 注册:当服务器启动的时候,会将自己的服务器信息,通过别名 ...
- centos7环境下安装nginx
安装所需环境 nginx是C语言开发,在Linux和windows环境上面都可以运行. 1.gcc安装 安装nginx需要将官网下载的代码进行编译,编译依赖gcc环境,如果没有gcc环境,需要先安装g ...
- 利用Python批量重命名文件夹下文件
#!/usr/bin/python # -*- coding: UTF-8 -*- # -*- coding:utf8 -*- import os from string import digits ...