Bone Collector

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

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<iostream>
#include<stdio.h>
using namespace std;
const int maxx = 1005;
int main(){int t;scanf("%d",&t);while(t--){int n,v;scanf("%d%d",&n,&v);int val[maxx];int wei[maxx];for(int i=1;i<=n;i++){scanf("%d",&val[i]);}for(int i=1;i<=n;i++){scanf("%d",&wei[i]);}int dp[maxx][maxx];for(int i=0;i<=v;i++)dp[0][i]=0;for(int i=1;i<=n;i++){for(int j=0;j<=v;j++){if(j<wei[i]){dp[i][j]=dp[i-1][j];}else{dp[i][j]=max(dp[i-1][j],dp[i-1][j-wei[i]]+val[i]);}}}printf("%d\n",dp[n][v]);}
}

View Code

转载于:https://www.cnblogs.com/superxuezhazha/p/5704210.html

hdu 2602 Bone Collector 01背包相关推荐

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

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

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

    Bone Collector Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Desc ...

  3. hdu 2602 Bone Collector(01背包)

    题意:给出包裹的大小v,然后给出n块骨头的价值value和体积volume,求出一路下来包裹可以携带骨头最大价值 思路:01背包 1.二维数组(不常用 #include<iostream> ...

  4. hdu 2602 Bone Collector 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 在没学01背包时做的,很遗憾的是,wa了很多次. wa代码 1 #include <ios ...

  5. hdu 2602 Bone Collector

    终于开始做自己一直不敢碰的dp了,内心颇不平静.很久以前看过的背包九讲也没什么印象了.这个题错了四次.之前老师有说过看到dp不要把它想成dp,要按照数学归纳的路子来.先来个最初的归纳假设,如果过弱再加 ...

  6. HDU 2602 Bone Collector - from lanshui_Yang

           题目大意:有n件物品,每件物品均有各自的价值和体积,给你一个容量为 V 的背包,问这个背包最多能装的物品的价值是多少?        解题思路:这是一道0 - 1 背包的简单模板题,也是 ...

  7. HDU - 2639 Bone Collector II

    HDU - 2639 Bone Collector II dp之难,难于上青天. The title of this problem is familiar,isn't it?yeah,if you ...

  8. HD 2602 Bone Collector (0-1背包)

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

  9. HDU 2602.Bone Collector-动态规划0-1背包

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

最新文章

  1. 如何点击TextField不弹出键盘?
  2. python在中小学教学中的应用-中小学Python编程语言教学
  3. 微软MVP社区夏日巡讲诚邀您的参与: 北京,上海,西宁,成都,西安
  4. matlab 小技巧
  5. 大话数据结构07 :链表栈
  6. 1到100的二进制编码_每天经过100天的编码后,我学到了什么
  7. 数据的统计分析与描述
  8. Mysql学习总结(44)——Linux下如何实现mysql数据库每天自动备份定时备份
  9. Sharding-JDBC水平分库(水平数据库分片策略配置)_Sharding-Sphere,Sharding-JDBC分布式_分库分表工作笔记010
  10. 在按钮上绑定一个图案
  11. CVPR2021 | 视频超分辨率中时空蒸馏方案
  12. 浪曦struts2学习笔记2
  13. AirServer 7win/mac手机投屏到电脑工具
  14. Java1.8开始为什么用元空间替换永久代
  15. 我是一个将近30岁的女程序员
  16. 在win7系统 Keil 开发环境下 Jlink 仿真器连不上解决办法
  17. 经典文献阅读之--PON
  18. diy 服务器 支持 esxi,【我的技术我做主】IT屌丝DIY ESXI虚拟化服务器再度升级ESXI6.0...
  19. Eclipse菜单project用法介绍
  20. sv中program和module区别

热门文章

  1. 【知识碎片】Asp.Net 篇
  2. 九、linux文件系统
  3. linux下C++动态链接C++库示例详解
  4. ASP.NET如何给控件增加属性?
  5. TSVNCache占用CPU的解决办法
  6. 【转】“根级别上的数据无效”问题的解决
  7. ASP的Server.UrlEncode和Asp.Net的Server.UrlEncode的返回结果不同
  8. 第二阶段第七次站立会议
  9. UVa 814 - The Letter Carrier's Rounds
  10. Visual Studio 正则表达式替换