Bone Collector

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 52296    Accepted Submission(s): 22040

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背包
 //2016.9.6
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int N = ;
int dp[N], c[N], w[N]; int main()
{
int T, n, v;
cin>>T;
while(T--)
{
scanf("%d%d", &n, &v);
memset(dp, , sizeof(dp));
for(int i = ; i < n; i++)
scanf("%d", &w[i]);
for(int i = ; i < n; i++)
scanf("%d", &c[i]);
for(int i = ; i < n; i++)
for(int j = v; j >= c[i]; j--)
dp[j] = max(dp[j], dp[j-c[i]]+w[i]);
printf("%d\n", dp[v]);
} return ;
}

HDU2602(背包)的更多相关文章

  1. hdu-2602&&POJ-3624---01背包裸题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 https://vjudge.net/problem/POJ-3624 都是01背包的裸题 这 ...

  2. HDU2602 Bone Collector(01背包)

    HDU2602 Bone Collector 01背包模板题 #include<stdio.h> #include<math.h> #include<string.h&g ...

  3. [原]hdu2602 Bone Collector (01背包)

    本文出自:http://blog.csdn.net/svitter 题意:典型到不能再典型的01背包.给了我一遍AC的快感. //=================================== ...

  4. HDU2602 Bone Collector 【01背包】

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

  5. hdu2602 Bone Collector (01背包)

    本文来源于:http://blog.csdn.net/svitter 题意:典型到不能再典型的01背包.给了我一遍AC的快感. //================================== ...

  6. hdu2602 Bone Collector 01背包

    Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like ...

  7. hdu2602 DP (01背包)

    题意:有一个容量 volume 的背包,有一个个给定体积和价值的骨头,问最多能装价值多少. 经典的 01 背包问题不谈,再不会我就要面壁了. 终于有一道题可以说水过了 ……心好累 #include&l ...

  8. 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 ...

  9. 解题报告:hdu2602 Bone collector 01背包模板

    2017-09-03 15:42:20 writer:pprp 01背包裸题,直接用一维阵列的做法就可以了 /* @theme: 01 背包问题 - 一维阵列 hdu 2602 @writer:ppr ...

随机推荐

  1. HttpClient 教程 (二)

    第二章 连接管理 HttpClient有一个对连接初始化和终止,还有在活动连接上I/O操作的完整控制.而连接操作的很多方面可以使用一些参数来控制. 2.1 连接参数 这些参数可以影响连接操作: 'ht ...

  2. POJ 3186 Treats for the Cows

    简单DP dp[i][j]表示的是i到j这段区间获得的a[i]*(j-i)+... ...+a[j-1]*(n-1)+a[j]*n最大值 那么[i,j]这个区间的最大值肯定是由[i+1,j]与[i,j ...

  3. spring加载过程中jar包加载不了,解决方法

    当我们在开发spring项目时,一般会将jar包放到webInf/lib下,这样是myeclipse自动将jar包加载到tomcat中webapps下,但是当我们新建一个lib文件夹的情况下,我们ad ...

  4. CDN概念+作用+特点+原理

    CDN的全称是Content Delivery Network,即内容分发网络.其目的是通过在现有的Internet中增加一层新的网络架构,将网站的内容发布到最接近用户的网络"边缘" ...

  5. Unity中的CG编写Shader系列(Blend)

    1.不透明度 当我们要将两个半透的纹理贴图到一个材质球上的时候就遇到混合的问题,由于前面的知识我们已经知道了片段着色器以及后面的环节的主要工作是输出颜色与深度到帧缓存中,所以两个纹理在每个像素上的颜色 ...

  6. HDU 2809 God of War

    状压DP.我认为是数据水了,用打死了哪几只作为状态,AC代码只需要保存当前状态的最大血量,完全没有考虑攻击力大小. 个人认为正确DP应该这样的:dp[状态][等级],但这样写不能AC,时间复杂度会很大 ...

  7. 170112、solr从服务器配置整合到项目实战

    整合网上资源后 100%可运行的配合步骤,部署在tomcat 为例. 一:下载solr,版本为5.2.1 地址:http://pan.baidu.com/s/1eRAdk3o 解压出来. 1.在解压的 ...

  8. 《算法导论》2.3-7 检查集合中是否存在两数字和为指定的X--算法和证明

    习题2.3-7:设计一个算法,对于一个给定的包含n个整数的集合S和另一个给定的整数X,该算法可以在时间内确定S中是否存在两个元素,使得它们的和恰为X. 解题思路:首先应该想到的是先用一个的排序算法对S ...

  9. 一种比较简单的在USB U盘中访问nandflash的方法

    u8 nandflash_write_buffer[NAND_SERECT_FULL_SIZE]; static int currentBlock = -1; static int currentPa ...

  10. iOS开发之指纹解锁

    http://blog.csdn.net/hongfengkt/article/details/49868073 前一阵子一直在赶项目进度,没有太多时间写博客,现在终于空闲了,将以前欠下的博客补上来. ...