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. async 异步流程控制规则

    github 学习async网址 : https://github.com/caolan/async/ 1.Async 函数介绍 async 主要实现了三个部分的流程控制功能 1.集合:Collect ...

  2. AltiumDesignerSummer9Build9.3.1.19182破解图文教程

    一.下载 AltiumDesignerSummer9Build9.3.1.19182 下载地址 http://www.verycd.com/topics/2769819/ 二.安装 一路确定啥的傻瓜式 ...

  3. 【给你几个使用Xamarin的理由】

    写在开篇前 这种代理操作,绑定影射的机制,有些极端的开发者确实难以接受.追求完美,总感觉原生的各种优点. 如果你非得较这个真,那您还是感觉补习下 Java Eclipse  ,买一台Mac 恶补Obj ...

  4. EBS收单方/收货方

    select rt.name, hcas.org_id from ar.hz_cust_acct_sites_all hcas, ar.hz_cust_site_uses_all hcsu, ra_t ...

  5. HashMap非线程安全分析

    通过各方资料了解,HashMap不是线程安全的,但是为什么不是线程安全的,在什么情况下会出现问题呢? 1. 下面对HashMap做一个实验,两个线程,并发写入不同的值,key和value相同,最后再看 ...

  6. 在CDHtmlDialog中处理WindowClosing

    要截获window.close(),就得截获CDHtmlDialog的WindowClosing.以下是示例代码: // header DECLARE_EVENTSINK_MAP() void Win ...

  7. Unity重要的函数

    Awake 当一个脚本实例被载入时Awake被调用. Start Start仅在Update函数第一次被调用前调用. Update 当MonoBehaviour启用时,其Update在每一帧被调用. ...

  8. Linux用户管理(笔记)

    用户:UID, /etc/passwd组:GID, /etc/group 影子口令:用户:/etc/shadow组:/etc/gshadow 用户类别:管理员:0普通用户: 1-65535    系统 ...

  9. pyQt事件处理

    Qt事件处理01 Qt处理事件的第二种方式:"重新实现QObject::event()函数",通过重新实现event()函数,可以在事件到达特定的事件处理器之前截获并处理他们.这种 ...

  10. Visual Studio 2015 使用ODP.net进行EF开发

    刚转了新公司,以前公司都是用VS+MSSQL作为开发工具的 现在新公司由于数据库是Oracle,而且新公司比较小规模,开发团队也没有什么规范 访问数据库的方式一直使用ADO.net的DataTable ...