HDU 2602.Bone Collector-动态规划0-1背包
Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 85530 Accepted Submission(s): 35381
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 ?

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.
5 10
1 2 3 4 5
5 4 3 2 1
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
int val[N],wei[N],dp[N];
int main(){
int t,n,m;
scanf("%d",&t);
while(t--){
memset(val,,sizeof(val));
memset(wei,,sizeof(wei));
memset(dp,,sizeof(dp));
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
scanf("%d",&val[i]);
for(int i=;i<n;i++)
scanf("%d",&wei[i]);
for(int i=;i<n;i++){
for(int j=m;j>=wei[i];j--){
dp[j]=max(dp[j],dp[j-wei[i]]+val[i]);
}
}
printf("%d\n",dp[m]);
}
return ;
}
代码(二维数组):
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+;
int val[N],wei[N],dp[N][N];
int main(){
int t,n,m;
scanf("%d",&t);
while(t--){
memset(dp,,sizeof(dp));
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
scanf("%d",&val[i]);
for(int i=;i<=n;i++)
scanf("%d",&wei[i]);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(wei[i]<=j)dp[i][j]=max(dp[i-][j],dp[i-][j-wei[i]]+val[i]);
else dp[i][j]=dp[i-][j];
}
}
printf("%d\n",dp[n][m]);
}
return ;
}
HDU 2602.Bone Collector-动态规划0-1背包的更多相关文章
- HDU 2602 Bone Collector (简单01背包)
Bone Collector http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , i ...
- HDU 2602 Bone Collector 0/1背包
题目链接:pid=2602">HDU 2602 Bone Collector Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...
- HDOJ(HDU).2602 Bone Collector (DP 01背包)
HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...
- hdu 2602 Bone Collector(01背包)模板
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 2602 Bone Collector(经典01背包问题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/O ...
- HDU 2602 Bone Collector
http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 2602 Bone Collector 背包入门题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 题目分析:0-1背包 注意dp数组的清空, 二维转化为一维后的公式变化 /*Bone Coll ...
- HDU 2602 Bone Collector(01背包裸题)
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 2602 - Bone Collector - [01背包模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a ...
- 题解报告:hdu 2602 Bone Collector(01背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , in Teddy’s ...
随机推荐
- laravel5.5缓存系统
目录 1 Redis的配置 1.1 安装PRedis 1.2 配置 1.2.1 配置redis数据库 1.2.2 更改session的配置 1.2.3 更改cache配置 1.3 使用redis 2 ...
- 使用Windows SFC和DISM工具来解决服务器OS问题
TechTarget中国原创] 随着使用时间的越来越多,Windows服务器安装的系统文件可能会被损坏或损毁.管理员一般可以通过系统自带的System File Checker (SFC) 或者更健壮 ...
- Jenkins拾遗--第一篇(安装Jenkins)
起因 近期由于工作需要做起了起了jenkins的维护.不做不知道,一搞发现里边全是小坑.两个月弄了一身泥.曾经小瞧了它,但是发现其实要弄好它不是那么容易的.有句知名的话"没有总结就没有提高. ...
- linux备忘录-基本命令
基本命令 将命令分类为获取信息类,文件管理类,目录管理类,文本处理类,系统类,工具类. 获取信息类 uname # 输出所有信息 # 一行输出,空格分割 uname -a # 输出内核名称 uname ...
- Hibernate 查询方法
1.简单查询: public User select(User user) { User newUser; try { newUser = (User) session.get(User.class, ...
- [译]如何去除pandas dataframe里面的Unnamed的列?
原文来源: https://stackoverflow.com/questions/43983622/remove-unnamed-columns-in-pandas-dataframe 问:我有一个 ...
- HDU 1532 基础EK Drainage Ditches
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 使用pdb模块调试Python
在Python中,我们需要debug时,有三种方式: 加log语句.最简单的方式是添加print()语句来输出我们想要获知的状态或者变量,好处是简单容易操作,坏处是debug完了之后,还需要将prin ...
- resultMap与resultType的区别等容易混淆的概念
都是为了表示结果集与java对象的关系 resultType只能通过属性与列的名称进行对应,并且大小写不敏感 resultType也可以是map(这样写会大小写敏感),不是自定义类型也行 result ...
- IPV6地址格式分析
IPV6地址格式分析 IPv6的地址长度是128位(bit). 将这128位的地址按每16位划分为一个段,将每个段转换成十六进制数字,并用冒号隔开. 例如:2000:0000:0000:0000:00 ...