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
 #include<cstdio>
#include<algorithm>
using namespace std;
long long dp[+];
int w[],p[];
int main()
{
int t,N,W;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&N,&W);
for(int i=;i<=N;i++) //
scanf("%d",&p[i]);
for(int i=;i<=N;i++) //
scanf("%d",&w[i]);
for(int i=;i<=W;i++)
dp[i]=;
for(int i=;i<=N;i++) // 这几个地方i开头值注意一样 错了几次..
{
for(int j=W;j>=w[i];j--)
{
dp[j]=max(dp[j],dp[j-w[i]]+p[i]); //核心代码
}
}
printf("%lld\n",dp[W]); } return ;
}

【模板--完全背包】HDU--2602 Bone Collector的更多相关文章

  1. HDU 2602 Bone Collector 0/1背包

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

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

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

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

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

  4. HDU 2602 Bone Collector

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

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

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

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

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

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

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

  8. hdu 2602 Bone Collector 背包入门题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 题目分析:0-1背包  注意dp数组的清空, 二维转化为一维后的公式变化 /*Bone Coll ...

  9. HDU 2602 Bone Collector(01背包裸题)

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

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

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

随机推荐

  1. 按enter 进行搜索 enter提交表单

    //按enter 进行搜索 document.onkeydown = function(e){ var ev = document.all ? window.event : e; if(ev.keyC ...

  2. thinkphp3.2自定义常量

    在项目文件夹 (如:Home) 中的Common文件夹下新建function.php //thinkphp3.2.2版本加入如下语句: define('XXX', XXX); //第一个参数是常量名, ...

  3. 【hexo】如何在一个小时内搭载个人博客

    版权申明:本文为博主原创文章,未经博主允许不得转载.如需转载,请私聊博主. 什么是hexo Hexo是一个开源的静态博客生成器,用node.js开发,作者是台湾大学生tommy351. 前期准备 安装 ...

  4. 遇到的Mysql的一个坑

    自己写的Java代码怎么也无法操作MySQL的写操作,打印SQL语句没有问题,检查连接也没有问题,最后手动写了一条记录,发现主键重复了,但是当时表是空的!所以就很震惊,于是选择删表重新来一次,这回成功 ...

  5. python实现折半查找算法&&归并排序算法

    今天依旧是学算法,前几天在搞bbs项目,界面也很丑,评论功能好像也有BUG.现在不搞了,得学下算法和数据结构,笔试过不了,连面试的机会都没有…… 今天学了折半查找算法,折半查找是蛮简单的,但是归并排序 ...

  6. Django 学习笔记(二)

    Django 第一个 Hello World 项目 经过上一篇的安装,我们已经拥有了Django 框架 1.选择项目默认存放的地址 默认地址是C:\Users\Lee,也就是进入cmd控制台的地址,创 ...

  7. JavaScript一个简易枚举类型实现扑克牌

    <script type="text/javascript"> /** * 这个函数创建一个新的枚举类型,实参对象表示类的每个实例的名字和值 * 返回值是一个构造函数, ...

  8. mysql数据库定时备份

    最近要用到mysql备份,就写了shell脚本用于备份. #!/bin/bash #定义备份的数据库名称 database=*** #定义备份的时间 currTime=$(date +%Y%m%d) ...

  9. 了解Java基础原理

    Java 是1995年SUN公司推出的一门高级编程语言,是面向互联网的语言,WEB应用程序首选的语言(安卓底层,大数据hadoop框架用java编写,Spark用Scala编写,Scala用java写 ...

  10. AOP in dotnet :AspectCore的参数拦截支持

    距离上一篇AspectCore的介绍发布已经很长一段时间了,这篇文章也早该和大家见面,最近一直忙于适应新工作,并在业余时间有幸向何镇汐,Savorboard,农夫,AlexLEWIS等几位大牛请教学习 ...