Bone Collector

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

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
Recommend
lcy   |   We have carefully selected several similar problems for you:  1203 2159 2955 1171 2191 
状态转移方程:dp[i][j] = max{dp[i+1][j], dp[i+1][j-vol[i]]+val[i]};其中i表示第i个物品,j表示背包当前的容量,而数组中所存放的元素为在当前状态下的最大价值。通过下面的每个状态的最大值向上推。因此,最终的最大状态应该存放在dp[0][v]中。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 1000 + 10;
const int INF = 0x3f3f3f3f;
int  n, v, val[MAXN], vol[MAXN], dp[MAXN][MAXN];
int main() {int t; scanf("%d", &t);while (t--) {scanf("%d %d", &n, &v);for (int i = 0; i < n; i++) {scanf("%d", &val[i]);}for (int i = 0; i < n; i++) {scanf("%d", &vol[i]);}memset(dp, 0, sizeof(dp));for (int i = n - 1; i >= 0; i--) {for (int j = 0; j <= v; j++) {if (j < vol[i]) dp[i][j] = dp[i + 1][j];else dp[i][j] = max(dp[i+1][j], dp[i+1][j-vol[i]]+val[i]);}}printf("%d\n", dp[0][v]);}return 0;
}

转载于:https://www.cnblogs.com/cniwoq/p/6770830.html

HDU Problem 2062 Bone Collector【01背包】相关推荐

  1. hdu 2602 Bone Collector 01背包

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

  2. 【HDU - 2639】Bone Collector II (第K大背包,dp,STLset)

    题干: The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rookie Cup ...

  3. hdu 6149 Valley Numer II(01背包套状压dp)

    题目链接:hdu 6149 Valley Numer II 题意: 给你N个点,有k个为高点,其他为低点,现在这N个点有m条边,问你最多能组成多少个两个高点一个低点,低点和两个高点都有边相连这样的状态 ...

  4. hdu 1864 最大报销额01背包dp

     最大报销额 Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Subm ...

  5. hdu 2546 饭卡(01背包)

    题意:只要最后留下的钱够5元,就可以买下最贵的食物,使得余额最低,其他的钱的使用就是一个最大背包问题了. 代码: #include<iostream> #include<cstrin ...

  6. HDu 3449 (有依赖的01背包) Consumer

    题意: 有n件物品,对应有不同的价格和价值,这是典型的01背包.但现在有了一个限制,要买物品先买能装这件物品的特定的盒子,盒子的价值为0 代码理解得还不是太好,感觉这是一个"二重" ...

  7. hdu 6092 Rikka with Subset 01背包 思维

    dp[i][j]表示前i个元素,子集和为j的个数.d[i][j] = d[i][j] + d[i-1][j-k] (第i个元素的值为k).这里可以优化成一维数组 比如序列为 1 2 3,每一步的dp值 ...

  8. HDU Bone Collector (01背包问题)

    之前背包问题学了忘学了忘= =是太笨了. 题目 许多年前,在泰迪的家乡,有一个人被称为"骨收集者".这个人喜欢收集各种骨头,例如狗,牛的骨头,他也去了坟墓-- 骨头收集者有一个大袋 ...

  9. hdu 2546 饭卡【01背包】

    题目链接:https://vjudge.net/contest/103424#problem/C 饭卡                                Time Limit: 5000/ ...

最新文章

  1. Java绘图之AWT中的继承关系图
  2. 总结CSS3新特性(媒体查询篇)
  3. Java会话技术之 —— cookie与session
  4. jQuery .tmpl(), .template()学习
  5. 德国黑客使用租用的计算机资源攻击散列算法
  6. 为JavaScript日期添加天数
  7. sap 中migo收货自动打印smartform_EWM MES/ERP集成 生产收货的几种方式
  8. 权限管理----用户与模块关系
  9. 【合天网安】SQLi-Labs系列之数字型报错注入
  10. element Table+Pagination实现分页
  11. 王家林Spark视频
  12. C#版OPCClient代码总结
  13. 编程实现在IntAct数据集上批量查找蛋白交互对
  14. Excel数据可视化——隐藏相同数据
  15. Android 5.0 CardView 应用
  16. python更复杂的输出格式
  17. l05173芯片针脚图_芯片引脚定义
  18. 手机系统暗潮汹涌 Symbian将何去何从?
  19. Android:MTK的Dialer模块联系人搜索
  20. 基于OFDM的水声通信系统设计

热门文章

  1. Linux下Tomcat重新启动以及日志
  2. spring五:获取容器中对象信息
  3. Zabbix 4.2 发布:支持Prometheus数据收集,可扩展性大大提升
  4. 为 Hyper-V 配置外部网络
  5. 为什么你不该用Timer
  6. OpenCV 中值滤波
  7. STC89C52单片机 使用定时器使LED灯闪烁
  8. HTML5手机端几秒钟自动跳转
  9. HTML5做手机站页面字体显示很小的解决方法
  10. linux c 调用 so 库