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
 模板题,找到状态转移方程,使用一维01背包,对于背包的体积要逆序遍历,这样是的右边的max(f[j],f[j-v[i]]+val[i])能够表示为上一层的状态,而对于当j<v[i时,默认f[j]不变,是上一层的值
 #include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
int T,V;
int v[],val[];
int f[];
int i,N,j;
cin>>T;
while(T--)
{
memset(f,,sizeof(f));
cin>>N>>V;
for(i=;i<=N;i++)
cin>>val[i];
for(i=;i<=N;i++)
cin>>v[i];
for(i=;i<=N;i++)
{
for(j=V;j>=v[i];j--)
f[j]=max(f[j],f[j-v[i]]+val[i]);
}
cout<<f[V]<<endl;
}
}

Bone Collector(ZeroOnebag)的更多相关文章

  1. hdu 2602 Bone Collector(01背包)模板

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...

  2. Bone Collector(01背包)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/N 题目: Description Many year ...

  3. 题解报告:hdu 2602 Bone Collector(01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , in Teddy’s ...

  4. HDU 2602 Bone Collector (简单01背包)

    Bone Collector http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , i ...

  5. 【01背包】HDU 2602 Bone Collector (模板题)

    Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bone C ...

  6. Hdu2602 Bone Collector (01背包)

    Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...

  7. hdu2602 Bone Collector(01背包) 2016-05-24 15:37 57人阅读 评论(0) 收藏

    Bone Collector Problem Description Many years ago , in Teddy's hometown there was a man who was call ...

  8. HDU 2602 Bone Collector(经典01背包问题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/O ...

  9. hdu 2602 - Bone Collector(01背包)解题报告

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

随机推荐

  1. Json.Net从4.0升级到7.0带来的问题

    1.由于被迫Json.Net升级,导致了我们一部分查询出来数据 2.分析原因result = JsonConvert.DeserializeObject(inputContent, JsonDataT ...

  2. MySQL导入较大sql文件报错max_allowed_packet

    1.查看当前最大允许导入sql文件大小 show VARIABLES like '%max_allowed_packet%'; 2.修改方式 1.永久生效 修改my.cnf文件 vim /etc/my ...

  3. 100个iOS开发/设计程序员面试题汇总,你将如何作答?

    100个iOS开发/设计程序员面试题汇总,你将如何作答? 雪姬 2015-01-25 19:10:49 工作职场 评论(0)   无论是对于公司还是开发者或设计师个人而言,面试都是一项耗时耗钱的项目, ...

  4. C和C++的学习过程总结

    总是被同学们问到,如何学习C和C++才不茫然,才不是乱学,想了一下,这里给出一个总的回复. 一家之言,欢迎拍砖哈. 1.可以考虑先学习C. 大多数时候,我们学习语言的目的,不是为了成为一个语言专家,而 ...

  5. 养成代码注释习惯,帮助你更好使用NetBeans导航器

    在使用NetBeans编写php代码时,为了在一个类中,或者在方法库文件中快速找到你想要找的函数或方法,通常我们会使用NetBeans的导航器. 我们看一个导航器的事例: 大家知道,在php中代码习惯 ...

  6. LeetCode_Path Sum II

    Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...

  7. 提高效率的便签By番茄时间管理 win7标签,小功能,大作用

    今日待办 把一些重要的事情,列入其中. 着重处理. 活动清单 罗列一些最近需要做的事情,不一定按照紧急重要的程度. 把活动清单中的事情,按照实际情况,安排到今日待办当中. 还有一个我喜欢的'头脑风暴' ...

  8. UESTC_王之盛宴 2015 UESTC Training for Graph Theory<Problem K>

    K - 王之盛宴 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  ...

  9. HDOJ-1016 Prime Ring Problem(DFS)

    http://acm.hdu.edu.cn/showproblem.php?pid=1016 题意:输入n,代表有一个包含n个节点的环,在环中的节点中填入1,2...n-1,n,要求填入的数与左边的数 ...

  10. 本地存储组件--兼容IE低版本

        在前端开发过程中,会用到本地缓存,但是由于浏览器对不同规范支持的程度不一样,每次进行使用都要为兼容行花费不少时间.我整理了一个本地存储的组件.     组件特点: 可以配置使用localSto ...