题目:
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 2 31).
Sample Input

 
        1
5 10
1 2 3 4 5
5 4 3 2 1 

Sample Output

 
        14 

Hint

By AC_gsws

解题思路:这个是典型的0-1背包问题,主要的代码是这几行
其中的w[i]数组是每种骨头的重量(weight),v[i]数组是每种骨头的价值(value),dp[i][j]是表示已加入i种骨头,背包的容量还剩j的时候能够得到的最优价值。初始化dp数组为0,然后从背包容量从最大容量开始计算,知道最后递推出最优答案。
AC代码:
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int T;
int m, n;
const int maxn = 1010;
int dp[maxn][maxn], v[maxn], w[maxn];
int main()
{scanf("%d", &T);while (T--){scanf("%d%d", &n, &m);memset(dp, 0, sizeof(dp));for (int i = 1; i <= n; i++){scanf("%d", &v[i]);}for (int j = 1; j <= n; j++){scanf("%d", &w[j]);}for (int i = 1; i <= n; i++){for (int j = m; j >=0; j--){if (j < w[i]) dp[i][j] = dp[i - 1][j];else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);}}printf("%d\n", dp[n][m]);}return 0;
}

有问题欢迎私聊哦~么么哒

简单dp-bone collector相关推荐

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

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

  2. HDU2602 Bone Collector【0/1背包+DP】

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

  3. NUC-ACM/ICPC 寒假训练 简单DP A - G题

    第一题:数塔 HDU - 2084 做法: 从第 i , j 个 节点往下走的最优解可以由从第 i+1,j 个节点往下走的最优解和第i+1,j+1个节点往下走的最优解得出,二者取其优即可. 代码: 记 ...

  4. hdu 2602 Bone Collector 01背包

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

  5. HDU Problem 2062 Bone Collector【01背包】

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

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

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

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

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

  8. Bone Collector(HDU-2602)

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

  9. Bone collector//动态规划

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

  10. Bone Collector(01背包问题-两种写法)

    Many years ago , in Teddy's hometown there was a man who was called "Bone Collector". This ...

最新文章

  1. Swift 圆环进度条
  2. DIY Ruby CPU 分析 Part III
  3. python能够做什么软件-python爬虫软件有哪些做的比较好的?
  4. linux generic什么意思_如何在 Ubuntu 中修复 VirtualBox 的 “rc=1908” 错误 | Linux 中国...
  5. Java程序员技能树
  6. 孙鑫VC学习笔记:第十三讲 (六) 关于释放内存
  7. 2011年工作安排_计算机技术与软件专业技术资格考试
  8. 通过自定义注解+反射的形式,使用POI实现excel的导入导出
  9. LC-3简易四子棋(深大计系1实验4) 思路+代码+详细注释
  10. 基于TensorRT和onnxruntime下pytorch的Bert模型加速对比实践
  11. c++ findpeaks函数_C++实现MATLAB一维数组函数findpeaks()函数求一维离散值极值(波峰波谷)...
  12. re 正则表达式匹配中文
  13. LeetCode05最长回文子串
  14. math: 凸函数、拟凸函数和保凸运算
  15. 【量化投资】高频交易(HFT),下一个风口?
  16. Dynamics 365 On-premises Field Service的安装试用问题
  17. html仿短信聊天,前端开发JS模仿手机短信发送
  18. 如何挖掘网站的长尾关键词?
  19. json和字典之间的转换
  20. 视野:产业链,价值链,核心竞争力

热门文章

  1. 【iOS】——暑假第二周3Gshare总结
  2. 怎样制作EDIUS底屏游走字幕?
  3. plsql最多可以存多少_酱酒瓶存与坛存的品质区别及风格变化
  4. 管壁式换热器cad图纸_关于换热器技术问答
  5. android反编译修改教程,反编译教程
  6. uboot联网以及uboot重启问题
  7. 删除磁盘中某个EFI系统分区
  8. 象QQ早上那样的新闻切换
  9. 【目标跟踪】算法C-COT中文翻译
  10. 阿里P8的《MySQL学习笔记》火了,完整版开放下载!