Hdoj 2602.Bone Collector 题解
Problem Description
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 ?

Input
The 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.
Output
One integer per line representing the maximum of the total value (this number will be less than 231).
Sample Input
1
5 10
1 2 3 4 5
5 4 3 2 1
Sample Output
14
Author
Teddy
Source
HDU 1st “Vegetable-Birds Cup” Programming Open Contest
思路
简单的01背包问题。
因为不用恰好装满,所以初始化的时候\(f[i]\)全都初始化为0
代码
#include<bits/stdc++.h>
using namespace std;
int value[1001];
int cost[1001];
int f[1001];
int main()
{
int T;
cin >> T;
while(T--)
{
int n,v;
cin >> n >> v;
memset(f,0,sizeof(f));
for(int i=1;i<=n;i++) cin >> value[i];//价值
for(int i=1;i<=n;i++) cin >> cost[i];//花费
for(int i=1;i<=n;i++)
for(int j=v;j>=cost[i];j--)
f[j] = max(f[j], f[j-cost[i]]+value[i]);
cout << f[v] << endl;
}
return 0;
}
Hdoj 2602.Bone Collector 题解的更多相关文章
- hdoj - 2602 Bone Collector
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...
- hdoj 2602 Bone Collector 【01背包】
意甲冠军:给出的数量和袋骨骼的数,然后给每块骨骼的价格值和音量.寻求袋最多可容纳骨骼价格值 难度;这个问题是最基本的01背包称号,不知道的话,推荐看<背包9说话> AC by SWS 主题 ...
- 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
http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 2602 Bone Collector 0/1背包
题目链接:pid=2602">HDU 2602 Bone Collector Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...
- 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(01背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , in Teddy’s ...
- HDU 2602 - Bone Collector - [01背包模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a ...
随机推荐
- MySQL优化技巧总结
MySQL优化的几个大方向 ① 硬件优化 ② 对MySQL配置参数进行优化(my.cnf)此优化需要进行压力测试来进行参数调整 ③ SQL语句方面的优化 ④ 表方面的优化 硬件优化 cpu,内存, ...
- 【转】Restful是什么
REST的概念是什么 维基百科 表现层状态转换(REST,英文:Representational State Transfer)是Roy Thomas Fielding博士于2000年在他的博士论文 ...
- 多线程系列之十一:Two-Phase Termination模式
一,Two-Phase Termination模式 翻译过来就是:分两阶段终止 二,示例程序 public class CountupTread extends Thread { private lo ...
- React不同版本之间需要注意的地方
React Fiber react fiber指的是react16.0机器之后的版本,相对于之前的版本来说,这一个版本的更新做了很多的优化,所以和之前的版本中的用法可能会发生不同,所以,平常开发中,主 ...
- Linux系统中常用的命令汇总
日常开发,上线的服务器系统一般都是Linux系统,所以,熟练的掌握常用的命令操作就尤其的重要了 1) 查看某个服务的运行情况 (例如Redis) ps -ef | grep redis //e-显示程 ...
- 05 Hadoop 设置块的大小
1.是在hdfs的配置文件中配置 2.是在app程序中设置 注意:假设配置文件的最大是 20K 最小是 10K 文件大小为72 块数就是 4 在程序中设置最大为15K 切割块数 ...
- Windows环境下在IDEA编辑器中spark开发安装步骤
以下是windows环境下安装spark的过程: 1.安装JDK(version:1.8.0.152) 2.安装scala(version:2.11/2.12) 3.安装spark(version:s ...
- mysql关联、子查询索引优化
1.驱动表:加索引不起作用,因为全表扫描.表1 left join 表2 ,此时表1是驱动表 被驱动表:给这个加索引. 关联查询 子查询时 尽量不使用not in 或者not exists 而是用 ...
- MCV 和 MTV框架基本信息
一 . MCV # web服务器开发最著名的MVC模式 M : model.py 就是和数据库打交道的, 创建表等操作 V : view 视图(视图函数,就是装HTML文件的) C : control ...
- Yii2的客户端验证
如何配置Yii的客户端验证呢? 首先,应该配置验证规则的场景,即scenario 其次,应该配置验证规则,在验证规则中配置客户端验证 例如: