题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602
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[i]=max(dp[i], dp[i-v[j]]+w[j]);

代码如下:

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;int main(){int v[1001],w[1001],dp[1001],t;scanf("%d",&t);while(t--){int p,n;memset(dp,0,sizeof(dp));scanf("%d%d", &n, &p);for(int i=0; i<n; ++i){scanf("%d",&w[i]);}for(int i=0; i<n; ++i){scanf("%d",&v[i]);}for(int j=0; j<n; ++j){for(int i=p; i>=v[j]; --i){//dp[i]表示将前j件物品放进容量为i的背包中的最大总价值 dp[i]=max(dp[i], dp[i-v[j]]+w[j]);}}printf("%d\n",dp[p]);}return 0;
}

HD 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. HDU Problem 2062 Bone Collector【01背包】

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

  6. Bone Collector【01背包】

    F - Bone Collector HDU - 2602 Many years ago , in Teddy's hometown there was a man who was called &q ...

  7. 2602 Bone Collector

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

  8. hdu 2602 Bone Collector 解题报告

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

  9. HDU 2602 Bone Collector - from lanshui_Yang

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

最新文章

  1. 低调的,我们改名字了!
  2. 2018 年都过去了,你还没有掌握用户运营的核心技巧?
  3. SpringBoot+MyBatis登录案例
  4. XCTF-高手进阶区:baby_web
  5. 自己写的一段预测双色球号码的Java代码
  6. html调用deeplink,如何优雅地从浏览器打开本地应用deeplink
  7. 使用layui的layer组件做弹出层
  8. 懒人图库-JS“焦点图”代码 漂亮的图片变化效果
  9. Exchange 2013SP1和O365混合部署系列一
  10. 一年中重要的节日列表_外贸干货 | 关于节日祝福与安排
  11. Bernoulli-Gaussian分布
  12. 数据挖掘导论——可视化分析实验
  13. 南方cass计算表面积_CASS在工程中的应用“计算表面积”的方法
  14. thrift开源项目研究
  15. 20145312 《信息安全系统设计基础》实验三 实时系统的移植
  16. springboot 企业微信申请域名验证: 将下载的文件( WW_verify_XXXXXX.txt)上传至填写域名根目录下
  17. sprint 1 的总结
  18. vmware 安装 黑群晖
  19. A*寻路算法,循序渐进,附完整源码
  20. 卸载electron-builder打包出来的应用,删除用户数据

热门文章

  1. 八城联动丨神策 2020 数据驱动用户大会「深圳场」10 月 22 日不见不散!
  2. 赛程一览 | 2019 上海国际创客大赛
  3. 【BZOJ 1877】 [SDOI2009]晨跑(费用流)
  4. JAVA关系表达式解析微引擎
  5. 微软修复Windows 10周年更新KB3194496累积更新安装问题
  6. 香蕉派路由功Openwrt、Android功耗对照測试
  7. posix多线程有感--API
  8. CLR Via CSharp读书笔记(14):字符、字符串和文本处理
  9. Blockchain Patent Players and domain
  10. career opportuties