hdu 2602 Bone Collector 背包入门题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602
题目分析:0-1背包 注意dp数组的清空, 二维转化为一维后的公式变化
/*Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 34192 Accepted Submission(s): 14066 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
*/
//ZeroOnePack
#include <cstdio>
#include <cstring>
const int maxn = + ;
int dp[maxn], n, v, wi[maxn], vi[maxn];
int Max(int a, int b)
{
return a > b ? a : b;
}
void ZeroOnePack(int C, int W)
{
for(int i = v; i >= C; i--)
dp[i] = Max(dp[i], dp[i-C]+W);
} int main()
{
int T;
scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &v);
for(int i = ; i <= n; i++) scanf("%d", &wi[i]);
for(int i = ; i <= n; i++) scanf("%d", &vi[i]);
memset(dp, , sizeof(dp)); //attention
for(int i = ; i <= n; i++)
ZeroOnePack(vi[i], wi[i]);
printf("%d\n", dp[v]);
}
return ;
}
hdu 2602 Bone Collector 背包入门题的更多相关文章
- 【01背包】HDU 2602 Bone Collector (模板题)
Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bone C ...
- HDOJ(HDU).2602 Bone Collector (DP 01背包)
HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...
- 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/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(经典01背包问题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/O ...
- 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 ...
随机推荐
- MySql5.5忘记root密码的解决方法
试了很多方法,下面这种方法是确保可以成功的,呵呵.转载自:http://hi.baidu.com/bjben/item/722bb50b27baf1dcdde5b097. 申明:本文章应该属于转载,但 ...
- [MongoDB] Query, update, index and group
/* 1. Query Operators */ db.posts.find({ viewsCount: {$get: 1000, $lte: 3000} }, {_id: 0, viewsCount ...
- MySQL Handler变量解析
http://blog.itpub.net/29254281/viewspace-1159014/ To see the effect of a query do the following st ...
- Linux开机执行顺序
1. 加载 BIOS 的硬件信息,并取得第一个开机装置的代号: 2. 读取第一个开机装置的 MBR 的 boot Loader (亦即是 lilo, grub 等等) 的开机信息: 3. 加载 K ...
- NDK debug模式
NDK默认是使用NDEBUG宏的,assert也默认不生效,若要开启assert,按以下步骤: 1.編譯NDK代碼時,後面加上NDK_DEBUG=1 ,如: ndk-build NDK_BUILD=1 ...
- set与hash_set
原文:http://blog.csdn.net/morewindows/article/details/7029587 STL系列之六 set与hash_set set和hash_set是STL中比较 ...
- windows下使用代理连接github
在公司的windows下使用github,因为github被墙,查了查,发现给在windows下的git制定代理很简单,一句话 git config --global http.proxy htt ...
- solr 范围查询
[]表示查询一个包括边界范围, {}表示查询一个不包括边界范围 A TO * 表示没有上界即>=A或是>A ,视使用的是[]还是{}而定 * TO A 表示没有下界即<=A或是< ...
- pyenv的安装和使用
1. 先安装crul和git sudo apt-get install curl git-core 2. 安装pyenv curl https://raw.github.com/yyuu/pyenv- ...
- Kinect For Windows V2开发日志三:简单的深度读取
代码示例: #include <Kinect.h> #include <iostream> using namespace std; int main(void) { IKin ...