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 ...
随机推荐
- iOS开发——开发必备OC篇&UITableView设置界面完整封装(三)
UITableView设置界面完整封装(三) 简单MVC实现UITableView设置界面之界面跳转 创建一个需要调整的对应的控制器 在需要调整的类型模型中创建对应的属性用来实现调整类型控制器的设置 ...
- JVM剖析
JVM剖析 这篇文章详细解释了Java虚拟机的内部架构.以下这幅图展示了Java虚拟机里面的关键组件(是依据Java SE 7版本的Java虚拟机). 这些组件将在下面的两个章节一一展开.第一章节涵盖 ...
- LMAX Disruptor – High Performance, Low Latency and Simple Too 转载
原文地址:http://www.symphonious.net/2011/07/11/lmax-disruptor-high-performance-low-latency-and-simple-to ...
- 如何让静态库中的可执行程序不调用的函数不链接进该可执行程序?(-ffunction-sections -Wl,--gc-sections)
关键词: -Wl,--gc-sections -ffunction-sections 链接 elf 库 有时我们会遇到这种情况,可执行程序需要链接一些静态库,但是静态库中的函数并没有全部使 ...
- scala的下划线
1.作为“通配符”,类似Java中的*.如import scala.math._ 2.:_*作为一个整体,告诉编译器你希望将某个参数当作参数序列处理!例如val s = sum(1 to 5:_*)就 ...
- iOS 10 推送必看(高阶1)
来源:徐不同 链接:http://www.jianshu.com/p/3d602a60ca4f iOS10 推送必看(基础篇) 虽然这篇文章比较长,也不好理解,但是还是建议大家收藏,以后用到的时候,可 ...
- python UTC,时间戳,字符串转换
#!/usr/bin/env python #_*_coding:utf-8_*_ # 本地时间 转换 为时间戳 import time import pytz import datetime dat ...
- 数据结构【三】:简单优先队列PriorityQueue
在数据结构[二]:简单阻塞队列BlockingQueue的基础上添加权限属性:priority,并控制enqueue时根据priority排序插入. 1.定义priority取值范围0~9 2.deq ...
- js中的命名规范
在实际开发中规范的命名,不仅方便自己查看,理解变量的实际意义,而且在团队开发中也能提高开发效率. 下面将介绍javascript中的变量的命名规范: 1)首先,变量名要有实际意义,不建议使用单个的字母 ...
- unity中js脚本与c#脚本互相调用
unity中js脚本与c#脚本互相调用 test1.js function OnGUI() { if(GUI.Button(Rect(25,25,100,30),"JS Call CS& ...