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


思路

简单的01背包问题。

因为不用恰好装满,所以初始化的时候\(f[i]\)全都初始化为0

代码

#include<bits/stdc++.h>
using namespace std;
int value[1001];
int cost[1001];
int f[1001];
int main()
{
int T;
cin >> T;
while(T--)
{
int n,v;
cin >> n >> v;
memset(f,0,sizeof(f));
for(int i=1;i<=n;i++) cin >> value[i];//价值
for(int i=1;i<=n;i++) cin >> cost[i];//花费
for(int i=1;i<=n;i++)
for(int j=v;j>=cost[i];j--)
f[j] = max(f[j], f[j-cost[i]]+value[i]);
cout << f[v] << endl;
}
return 0;
}

Hdoj 2602.Bone Collector 题解的更多相关文章

  1. hdoj - 2602 Bone Collector

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

  2. hdoj 2602 Bone Collector 【01背包】

    意甲冠军:给出的数量和袋骨骼的数,然后给每块骨骼的价格值和音量.寻求袋最多可容纳骨骼价格值 难度;这个问题是最基本的01背包称号,不知道的话,推荐看<背包9说话> AC by SWS 主题 ...

  3. HDOJ(HDU).2602 Bone Collector (DP 01背包)

    HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...

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

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

  5. HDU 2602 Bone Collector

    http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...

  6. HDU 2602 Bone Collector 0/1背包

    题目链接:pid=2602">HDU 2602 Bone Collector Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...

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

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

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

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

  9. HDU 2602 - Bone Collector - [01背包模板题]

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

随机推荐

  1. sql 表值函数与标量值函数

    写sql存储过程经常需要调用一些函数来使处理过程更加合理,也可以使函数复用性更强,不过在写sql函数的时候可能会发现,有些函数是在表值函数下写的有些是在标量值下写的,区别是表值函数只能返回一个表,标量 ...

  2. spring security运行流程图(转)

    原文:http://blog.csdn.net/u011511684/article/details/31394493 示例下载地址:http://download.csdn.net/detail/u ...

  3. py使用笔记-pandas函数

    1,nan替换为0df = df(np.nan, 0, regex=True)2.inf替换为0df= df(np.inf, 0.0, regex=True)3.从数据库读取数据到dataframei ...

  4. mysql cpu 100% 满 优化方案

    解决MySQL CPU占用100%的经验总结 - karl_han的专栏 - CSDN博客 https://blog.csdn.net/karl_han/article/details/5630782 ...

  5. Oracle创建'数据库'三步走

    --创建表空间 create tablespace waterboss datafile 'd:\waterboss.dbf' size 100m autoextend on next 10m; -- ...

  6. JavaMail入门第一篇 邮件简介及API概述

    现如今,电子邮件在我们的生活当中扮演着越来越重要的角色,我们每个人几乎都会与其打交道(至少时不时我们都会接收到莫名其妙的垃圾邮件),在工作中,使用邮件进行交流沟通,可以使我们的工作有迹可循,也显的较为 ...

  7. jenkins配置SSH远程服务器连接

    之前用jenkins做了一个自动发布测试,配置任务的Post Steps时,选择的是执行shell命令.如下图: 这是在本192.168.26.233服务器上测试的,此服务器上运行jenkins,to ...

  8. Windows 10 & change DNS

    Windows 10 & change DNS https://www.windowscentral.com/how-change-your-pcs-dns-settings-windows- ...

  9. DAY09、函数

    一.函数的定义:跟变量名的定义大同小异 1.声明函数的关键词:def 2.函数(变量)名:使用函数的依据 3.参数列表:()   参数个数可以为0到n个,但()一定不能丢,完成功能的必要条件 4.函数 ...

  10. NLP的原理,框架及具体实例

    1. 什么是NLP 所谓NLP就是自然语言处理,即计算机识别人的自然沟通语言,将人的语言转换成表达含义相同的文字.因为NLP的目的是将人和计算机通过自然语言沟通成为可能,而人最方便的沟通是通过语音发声 ...