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 ...
随机推荐
- 【opencv系列04】OpenCV4.X图形绘制
一. 基本图形绘制 1. 基本函数与参数 cv2.line(): 线 cv2.circle(): 圆 cv2.rectangle(): 矩形 cv2.ellipse(): 椭圆 cv2.putText ...
- python,keras,tensorflow安装问题 module 'tensorflow' has no attribute 'get_default_graph'
module ‘tensorflow’ has no attribute ‘get_default_graph’当我使用keras和tensorflow做深度学习的时候,python3.7报了这个错误 ...
- OpenCV-Python 理解特征 | 三十六
目标 在本章中,我们将尝试理解什么是特征,为什么拐角重要等等 解释 你们大多数人都会玩拼图游戏.你会得到很多小图像,需要正确组装它们以形成大的真实图像.问题是,你怎么做?将相同的理论投影到计算机程序上 ...
- OpenCV-Python 图像分割与Watershed算法 | 三十四
目标 在本章中, 我们将学习使用分水岭算法实现基于标记的图像分割 我们将看到:cv.watershed() 理论 任何灰度图像都可以看作是一个地形表面,其中高强度表示山峰,低强度表示山谷.你开始用不同 ...
- nginx 配置反向代理解决请求跨域问题
server { listen ; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; roo ...
- iOS提审笔记
查看苹果各大系统的服务状态:中国区服务:https://www.apple.com/cn/support/systemstatus/美国区服务:https://developer.apple.com/ ...
- Springmvc与Struts区别?
在一个技术群里看到机器人解释的二者区别,在此Mark下. 一.框架机制 spring mvc 和 struts2的加载机制不同:spring mvc的入口是servlet,而struts2是filte ...
- 12c OCR corrupted results in CRS stack down.
12c OCR corrupted results in CRS stack down. 1. check crsd.trc2017-03-21 16:14:44.667838 : CRSOCR:2 ...
- Python第三方包之PrettyTable
Python第三方包之PrettyTable 可以让我们将数据用表格的方式展示出来 安装方式 pip install PrettyTable 测试是否安装成功 使用方法与对比 增加一条数据 先简单的看 ...
- CentOS下的Docker离线安装
Linux下离线安装Docker 一.基础环境 1.操作系统:CentOS 7.3 2.Docker版本:18.06.1 官方下载地址(打不开可能很慢) 3.百度云Docker 18.06.1地址:h ...