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 ...
随机推荐
- [Angular2 Router] Using snapshot in Router
In the application, we have heros list, when click each hero, will redirect to hero detail view. Tha ...
- [Angular-Scaled Web] 7. Refactor code into Models
In the previous code, both categories and bookmarks are binded to $rootscope, or let says the same s ...
- 基于jQuery的图片相册滑出放大插件
今天给大家带来一款基于jQuery的图片相册滑出放大插件.点击相册图片,展示该图片.该插件适用浏览器:IE8.360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之窗..效 ...
- GCD调度组、自定义队列来实现多个下载任务
#define KURL1 @"http://img0.imgtn.bdimg.com/it/u=79920747,2237302485&fm=90&gp=0.jpg&quo ...
- C# 使用代码来操作 IIS
由于需要维护网站的时候,可以自动将所有的站点HTTP重定向到指定的静态页面上. 要操作 IIS 主要使用到的是“Microsoft.Web.Administration.dll”. 该类库不可以在引用 ...
- vb6.0如何让窗体跟随鼠标运动
首先将form的boderstyle属性设为0 Dim movesScreen As Boolean Dim mousX As Integer Dim mousY As Integer Dim cur ...
- oracle数据操纵语言(DML)data manipulation language
数据库操纵语言(DML)用于查询和操纵模式对象中的数据,它不隐式地提交当前事务. SELECTINSERTUPDATEDELETECALLEXPLAIN PLANLOCK TABLEMERGE使用算术 ...
- 分享一款简洁的jQuery轮播源码
<html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>无标题页</titl ...
- python中string模块各属性以及函数的用法
任何语言都离不开字符,那就会涉及对字符的操作,尤其是脚本语言更是频繁,不管是生产环境还是面试考验都要面对字符串的操作. python的字符串操作通过2部分的方法函数基本上就可以解决所有的字符串 ...
- QTREE2 spoj 913. Query on a tree II 经典的倍增思想
QTREE2 经典的倍增思想 题目: 给出一棵树,求: 1.两点之间距离. 2.从节点x到节点y最短路径上第k个节点的编号. 分析: 第一问的话,随便以一个节点为根,求得其他节点到根的距离,然后对于每 ...