题目链接:HDU 2602 Bone Collector

Bone Collector

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

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 2844 1087 

经典0/1背包问题。

有N件物品和一个容量为V的背包,第i件物品的体积为v[i],价值为w[i],求解将哪些物品装入背包才干使总价值最大。

这是最基础的背包问题,每种物品仅仅有一件。且仅仅有两种状态:放与不放。

用子问题定义状态:dp[i][v]表示前i件物品恰好放入一个容量为m的包中可获得的最大价值。

状态转移方程:dp[i][m] = max(dp[i-1][m], dp[i-1][m-v[i]]+w[i]);

可转化为一维情况:dp[m] = max(dp[m], dp[m-v[i]]+w[i]);

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;int n, v, dp[1010], value[1010], volume[1010];
int main()
{int t;scanf("%d", &t);while(t--){scanf("%d%d", &n, &v);for(int i = 1; i <= n; i++)scanf("%d", &value[i]);for(int i = 1; i <= n; i++)scanf("%d", &volume[i]);memset(dp, 0, sizeof(dp));for(int i = 1; i <= n; i++)for(int j = v; j >= volume[i]; j--)dp[j] = max(dp[j], dp[j-volume[i]]+value[i]);printf("%d\n", dp[v]);}return 0;
}

转载于:https://www.cnblogs.com/claireyuancy/p/7395512.html

HDU 2602 Bone Collector 0/1背包相关推荐

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

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

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

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

  6. hdu 2602 Bone Collector 解题报告

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

  7. HDU 2602 Bone Collector - from lanshui_Yang

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

  8. hdu 2602 Bone Collector

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

  9. HDU - 2639 Bone Collector II

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

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

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

最新文章

  1. as3(actionScript3.0) 操作摄像头(Camera)实例
  2. android 之多线程详解
  3. boost::hana::empty用法的测试程序
  4. springboot 关闭懒加载_SpringBoot新手入门篇
  5. [mybatis]动态sql_if_where_trim判断OGNL
  6. IT行业的你,在成本部门还是利润部门
  7. 顶会VLDB‘22论文解读:CAE-ENSEMBLE算法
  8. 没有资本怎么创业的思维:不是钱,是实现。
  9. 【Docker篇之三】Dockerfile创建镜像
  10. 融合记忆法的程序员高效自学方法
  11. 20200608模拟赛 Endless
  12. 手机网页图片自适应大小 background-size css 图片全屏 背景尺寸设置
  13. SAP那些事-职业篇-36-从“固定资产清理”科目说开去
  14. 处理Account locked due to 217 failed logins的问题
  15. 免费天气预报查询 API、历史天气查询 API 接口使用示例【源码可用】
  16. 30句感悟人生的格言名言
  17. 愿你也能每日早起,享受清晨的第一缕阳光
  18. 大数据产业发展前二十强城市
  19. openstack stein 部署大数据容器及prometheus
  20. 更适合小朋友的儿童节礼物,在CTWing找到了

热门文章

  1. UIKit 框架之UIScrollView
  2. 进程间通信——系统调用setjmp()与longjmp()
  3. MyBatis #{ } ${ }
  4. vim 复制到剪切板
  5. 不会优化数据库,早晚被优化!
  6. SpringBoot+RabbitMQ ,保证消息100%投递成功并被消费(实例)
  7. 分布式MySQL集群方案,看看京东是怎么做的
  8. Red Hat 发布新 logo:“没有脸了”
  9. Android开源项目推荐之「图片加载到底哪家强」
  10. python主线程执行回调函数_Python并发编程06 /阻塞、异步调用/同步调用、异步回调函数、线程queue、事件event、协程...