Bone Collector

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 27413    Accepted Submission(s): 11154

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背包。

AC代码例如以下:

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int t,n,v;
int i,j;
int a[1005],b[1005],dp[1005];
cin>>t;
while(t--)
{
cin>>n>>v;
for(i=1;i<=n;i++)
cin>>a[i];
for(i=1;i<=n;i++)
cin>>b[i];
memset(dp,0,sizeof dp);
for(i=1;i<=n;i++)
for(j=v;j>=b[i];j--)
dp[j]=max(dp[j-b[i]]+a[i],dp[j]);
cout<<dp[v]<<endl;
} return 0;
}

杭电 2602 Bone Collector的更多相关文章

  1. 杭电2602 Bone Collector

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

  2. 杭电2602 Bone Collector 【01背包】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 解题思路:给出一个容量为V的包,以及n个物品,每一个物品的耗费的费用记作c[i](即该物品的体积 ...

  3. 杭电 2639 Bone Collector II【01背包第k优解】

    解题思路:对于01背包的状态转移方程式f[v]=max(f[v],f[v-c[i]+w[i]]);其实01背包记录了每一个装法的背包值,但是在01背包中我们通常求的是最优解, 即为取的是f[v],f[ ...

  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. HDOJ(HDU).2602 Bone Collector (DP 01背包)

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

  9. Bone Collector------HDOJ杭电2602(纯01背包问题!!!!!!具体解释!)

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

随机推荐

  1. POJ2528 线段树的区间操作

    首先应该对该[0,10000000]进行离散化 即先将点集进行排序,然后从小到大缩小其中的间距,使得最后点数不会超过2*n 然后就是线段树操作 只需进行染色,然后最后用nlgn进行一个个查询颜色记录即 ...

  2. 记录遇到的IE8兼容性问题汇总

    1,伪元素:first-child不起作用,需要单独指定样式名称 2,透明度表示方法,尤其在函数中表示 @mixin opacity($value) { -webkit-opacity: $value ...

  3. maven pom.xml加载不同properties配置

    1.pom.xml =========================== <!-- 不同的打包环境配置: test=开发/测试测试环境,  product=生产环境; 命令行方式: mvn c ...

  4. FAT32文件系统--For TF卡

    1. TF卡空间是如何分配的? 下面以4GB TF卡为例,通过WinHex工具进行分析,其空间分配如下图所示: FAT32把目录当做文件来管理,所以没有独立的目录区,所有的文件目录项都是在数据区里面的 ...

  5. 别做操之过急的”无效将军”,做实实在在的”日拱一卒” zz

    别做操之过急的”无效将军”,做实实在在的”日拱一卒” 前天在网上看到一句话很不错,拿来和大家分享,同时用我的“大叔”三观来解读这句话. 这句话是:“我们不需要操之过急的”无效将军”,我们需要实实在在的 ...

  6. HDU 4521-小明序列(线段树好题)

    题意: n个数字的序列,求各数位置间隔大于d的最长上升子序列 分析: 最基本的dp但是数据量大O(n^2)肯定超时 前dp[i]为的最长上升子序列是由前dp[1]---dp[i-d-1]符合条件的最大 ...

  7. 京东拍拍网 笔试 搞java的去考C++ 苦逼

    1.用C实现数字逆转,用递归实现,很简单. package 京东; public class Main { private static int a=0; public static void fun ...

  8. [原]AngularJS iframe打开不同域的内容时报错误

    <iframe id="myFrame" ng-src="{{url}}" width="100%" height="100 ...

  9. NOIP2014 生活大爆炸版石头剪刀布

    生活大爆炸版石头剪刀布 (rps.cpp/c/pas) [问题描述] 石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负.在<生活大爆炸>第二季第8 ...

  10. 关于C#动态调用VC Dll的方法(转)

    http://blog.csdn.net/null1/article/details/3953155