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 ...
随机推荐
- Makes And The Product CodeForces - 817B (思维+构造)
B. Makes And The Product time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- oc之脚本
进入Build Phases页面,点击加号选择“New Run Script Phases”创建Run Script 在这里添加Run Script, 1.每次编译运行版本号(bundleVersio ...
- iOS上手指点击波纹效果的实现
https://www.jianshu.com/p/35e6f53ca0fe 2016.10.19 22:00* 字数 135 阅读 2468评论 2喜欢 7 闲暇时间做了一个反馈手指点击屏幕的效果, ...
- MySQL 主从同步遇到的问题及解决方案
在做某个项目的时候,使用主从数据库,master负责update.delete.insert操作,而slave负责select操作. 情景1:发表文章与查看文章 可以认为这个项目是一个博客系统,这里就 ...
- MySQL之数据导入导出
日常开发中,经常会涉及到对于数据库中数据的导入与导出操作,格式也有很多: TXT,CSV,XLS,SQL等格式,所以,在此总结一下,省的总是百度查询. 一 导出 1) 常用的方式就是使用现成的工具例如 ...
- JMeter学习non-gui模式运行
-h, --help print usage information and exit #打印帮助信息 -v, --version print the version information and ...
- Python3练习题 021:递归方法求阶乘
利用递归方法求5!. 方法一 f = 1 for i in range(1,6): f = f * i print(f) 方法二 import functools print(functo ...
- vue 使用sass 和less
npm i sass-loader --save -dev(-D)
- php分割中文字符串为数组的简单例子
近日在做东西时,遇到要把中文字符进行逐字分割,试了很多方法,都不行,后来发现了一个超简单的方法: 分割字符串很简单,主要是用到函数preg_match_all.当处理含有中文的字符串时,可以用如下的方 ...
- PHP爬虫框架Snoopy的使用
参考文档: http://ibillxia.github.io/blog/2010/08/10/php-connecting-tool-snoopy-introduction-and-applicat ...