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 ...
随机推荐
- android环境部署(1.1)
前言 对于android文件的解释和说明下载,这里分享一个博客大家了解吧.这里作者提供的下载地址可能有无效的,关键是解析..... 转自:http://www.cnblogs.com/bjzhangh ...
- RSA非对称算法(转)
RSA加密算法是最常用的非对称加密算法,CFCA在证书服务中离不了它.但是有不少新来的同事对它不太了解,恰好看到一本书中作者用实例对它进行了简化而生动的描述,使得高深的数学理论能够被容易地理解.我们经 ...
- Winform下实现图片切换特效的方法
本文实例讲述了Winform下实现图片切换特效的方法,是应用程序开发中非常实用的一个功能.分享给大家供大家参考之用.具体方法如下: 本实例源自网络,功能较为齐全.丰富!主要功能代码如下: using ...
- iOS 重力感应 学习1 陀螺仪 水平仪 指南针
小球可以随着重力感应 四处乱撞. 放大了坐标位移 就可以看见小球动了. 然后规定小球的路径 当滑到中间时候 弹出一张图片 作为提示. 我做了一个小demo 效果不错哦 CMMotionManager ...
- Android 常用 adb 命令
查看原文:http://blog.csdn.net/u010818425/article/details/52266593 (一)基础操作 安装app adb install -r xxx.apk / ...
- 常见的 HTTP错误代码大全
一些常见的状态码为: - 服务器成功返回网页 - 请求的网页不存在 - 服务不可用 详细分解: 1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 (继续) 请求者应当继 ...
- UIPickerView 简单操作和实际应用
1.UIPickerView 选择指示器控件 //选择器的初始化 UIPickerView * pickerView = [[UIPickerView alloc] initWithFrame:CGR ...
- 编译cordova-android代码
开发cordova-android的插件得引入cordova的jar包,网上打包好的参差不齐,也不一定是最新版本,下面我们自己打包 cordova的jar包. 1.clone代码 cordova-an ...
- QTREE2 spoj 913. Query on a tree II 经典的倍增思想
QTREE2 经典的倍增思想 题目: 给出一棵树,求: 1.两点之间距离. 2.从节点x到节点y最短路径上第k个节点的编号. 分析: 第一问的话,随便以一个节点为根,求得其他节点到根的距离,然后对于每 ...
- 【转载】Deep Learning(深度学习)学习笔记整理
http://blog.csdn.net/zouxy09/article/details/8775360 一.概述 Artificial Intelligence,也就是人工智能,就像长生不老和星际漫 ...