Bone Collector

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

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

注意:先输入每个骨头的价值然后输入每个骨头的体积。

状态转移方程:dp[j]=max(dp[j],dp[j-v[i]]+w[i]。

#include <iostream>
#include <string.h> using namespace std;
int N,V;
int dp[];
int w[],v[];
int main()
{
int t;
while(cin>>t){
while(t--){
cin>>N>>V;
for(int i=;i<=N;i++){
cin>>w[i];
}
for(int i=;i<=N;i++){
cin>>v[i];
}
memset(dp,,sizeof(dp));
for(int i=;i<=N;i++){
for(int j=V;j>=v[i];j--){ //j如果小于了v[i]那么v[i]一定无法装入袋子
dp[j]=max(dp[j],dp[j-v[i]]+w[i]);
}
}
cout<<dp[V]<<endl;
}
}
return ;
}

HDU2602Bone Collector 简单0-1背包的更多相关文章

  1. HDU1712简单的分组背包

    HDU1712http://acm.hdu.edu.cn/showproblem.php?pid=1712 简单的分组背包 #include <map> #include <set& ...

  2. P1417 烹调方案 (0/1背包+贪心)

    题目背景 由于你的帮助,火星只遭受了最小的损失.但gw懒得重建家园了,就造了一艘飞船飞向遥远的earth星.不过飞船飞到一半,gw发现了一个很严重的问题:肚子饿了~ gw还是会做饭的,于是拿出了储藏的 ...

  3. poj1417 带权并查集+0/1背包

    题意:有一个岛上住着一些神和魔,并且已知神和魔的数量,现在已知神总是说真话,魔总是说假话,有 n 个询问,问某个神或魔(身份未知),问题是问某个是神还是魔,根据他们的回答,问是否能够确定哪些是神哪些是 ...

  4. 洛谷 P1064 金明的预算方案 (有依赖的0/1背包)

    题目描述 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间金明自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过NN元钱就行”. ...

  5. POJ 1636 Prison rearrangement DFS+0/1背包

    题目链接: id=1636">POJ 1636 Prison rearrangement Prison rearrangement Time Limit: 3000MS   Memor ...

  6. POJ 1745 【0/1 背包】

    题目链接:http://poj.org/problem?id=1745 Divisibility Time Limit: 1000MS   Memory Limit: 10000K Total Sub ...

  7. 浙大PAT CCCC L3-001 凑零钱 ( 0/1背包 && 路径记录 )

    题目链接 分析 : 就是一个 0/1 背包,但是需要记录具体状态的转移情况 这个可以想象成一个状态转移图,然后实际就是记录路径 将状态看成点然后转移看成边,最后输出字典序最小的路径 这里有一个很巧妙的 ...

  8. 牛客网 TaoTao要吃鸡 ( 0/1背包变形 )

    题意 : 题目链接 分析 :  如果没有 BUG (即 h == 0 的时候)就是一个普通的 0 / 1 背包 需要讨论一下 h != 0 的情况 此时有就相当于有物品是有特权的 而且背包装有特权的物 ...

  9. HDU 2602 Bone Collector 0/1背包

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

随机推荐

  1. meta文件里指定资源

    unity的黑科技 https://github.com/keijiro/KinoFringe/tree/master/Assets/Kino 这个包里面 shader的绑定很有意思在meta里面 d ...

  2. Unity Dynamic Batching

    public class test1 : MonoBehaviour { public GameObject prefab; void Start() { ; i < ; i++) { Game ...

  3. iOS 带IAP提交注意事项及无法submit for review的解决方案

    原地址:http://blog.sina.com.cn/s/blog_71ce775e0101dl4a.html 最近项目接触到了苹果的程序内购(IAP),碰到不少问题,参考了很多帖子才得以解决.在此 ...

  4. pcap学习

    #include <pcap.h> char errbuf[PCAP_ERRBUF_SIZE]; pcap_t *pcap_open_live(const char *device, in ...

  5. Android 4.4 Kitkat Phone工作流程浅析(七)__来电(MT)响铃流程

    本文来自http://blog.csdn.net/yihongyuelan 转载请务必注明出处 本文代码以MTK平台Android 4.4为分析对象,与Google原生AOSP有些许差异,请读者知悉. ...

  6. Python 的基本运算和内置函数

    一.运算符 (一)Python算术运算符 以下假设变量: a=10,b=20: 运算符 描述 实例 + 加 - 两个对象相加 a + b 输出结果 30 - 减 - 得到负数或是一个数减去另一个数 a ...

  7. 【MyBatis】MyBatis分页插件PageHelper的使用

    好多天没写博客了,因为最近在实习,大部分时间在熟悉实习相关的东西,也没有怎么学习新的东西,这周末学习了MyBatis的一个分页插件PageHelper,虽然没有那么的强大(我在最后会说明它的缺点),但 ...

  8. webpack打包vue2.0项目时必现问题(转载)

    原文地址:http://www.imooc.com/article/17868 [Vue warn]: You are using the runtime-only build of Vue wher ...

  9. NSTimer 增加引用计数, 导致内存泄露,

    self.adTimer   = [NSTimerscheduledTimerWithTimeInterval:5.0target:selfselector:@selector(handleADIma ...

  10. PHP,mysql,Linux,CI框架学习总结

    PHP,mysql,CI框架学习总结 PHP标记 1.Xml风格<?php ?> 2.简短风格 <? ?> 需在php.ini中开启short_open_tag 3.asp风格 ...