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. DataTables选择行并删除(删除单行)

    $(document).ready(function() { var table = $('#example').DataTable(); $('#example tbody').on( 'click ...

  2. DSASync: Managing End-to-End Connections in Dynamic Spectrum Access Wireless LANs

    其实跟上一篇是同一篇文章.不过上一篇是发表在IEEE Secon2010了,这篇是后来又增加了部分内容后的一版,收录在IEEE/ACM TRANSACTIONS ON NETWORKING, VOL. ...

  3. rsyslog VS syslog-ng,日志记录哪家强?

    还有慢慢摸索,NG的MYSQL配置,我始终没搞好. RSYSLOG则比较容易. 另外,也可以每个RSYSLOG直接入库,不需要经过LOG SERVER..如果有一个大内网的话... 配合LOGANAL ...

  4. poj3294 --Life Forms

    Life Forms Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 12483   Accepted: 3501 Descr ...

  5. Qt5+VS2013兼容XP方法

    用Qt5+VS2013编译程序默认配置会在XP运行时报"不是有效的Win32程序"工作需要必须要XP运行 pro文件中加一句: 复制代码 QMAKE_LFLAGS_WINDOWS ...

  6. GBT28181中的RTP

    国标中说h264数据按照RFC3984打包,但是国标的测试工具——SPVMN,却不支持RFC3984的打包方式.无奈之下直接用RFC3550的方式打包,其实就是分包,然后加上RTP头,对于一帧的结束, ...

  7. Android Studio代码着色插件

    文章将给大家分享Studio中代码高亮插件,个人觉得换个代码着色方式还是挺有必要的,起码让视觉上有个变换,感官上爽一些.就像吃惯了大鱼大肉,偶尔也来点青菜萝卜吧.以下是个人喜欢的几款,给个效果图大家看 ...

  8. Hdu5785-Interesting(回文串处理)

    Problem Description Alice get a string S. She thinks palindrome string is interesting. Now she wanna ...

  9. jdbc连接数据库工具类

    import java.lang.reflect.Field; import java.sql.Connection; import java.sql.DriverManager; import ja ...

  10. Merlin 的魔力: SpringLayout 管理器

    摘自http://tech.it168.com/a2009/0211/265/000000265087_all.shtml 摘自http://cache.baiducontent.com/c?m=9f ...