HD 2602 Bone Collector (0-1背包)
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 ?
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.
状态转移方程为: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背包)相关推荐
- hdu 2602 Bone Collector(01背包)模板
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 2602 Bone Collector DP(01背包)
Bone Collector Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Desc ...
- hdu 2602 Bone Collector(01背包)
题意:给出包裹的大小v,然后给出n块骨头的价值value和体积volume,求出一路下来包裹可以携带骨头最大价值 思路:01背包 1.二维数组(不常用 #include<iostream> ...
- hdu 2602 Bone Collector 01背包
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU Problem 2062 Bone Collector【01背包】
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- Bone Collector【01背包】
F - Bone Collector HDU - 2602 Many years ago , in Teddy's hometown there was a man who was called &q ...
- 2602 Bone Collector
题目详情: Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 2602 Bone Collector 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 在没学01背包时做的,很遗憾的是,wa了很多次. wa代码 1 #include <ios ...
- HDU 2602 Bone Collector - from lanshui_Yang
题目大意:有n件物品,每件物品均有各自的价值和体积,给你一个容量为 V 的背包,问这个背包最多能装的物品的价值是多少? 解题思路:这是一道0 - 1 背包的简单模板题,也是 ...
最新文章
- 低调的,我们改名字了!
- 2018 年都过去了,你还没有掌握用户运营的核心技巧?
- SpringBoot+MyBatis登录案例
- XCTF-高手进阶区:baby_web
- 自己写的一段预测双色球号码的Java代码
- html调用deeplink,如何优雅地从浏览器打开本地应用deeplink
- 使用layui的layer组件做弹出层
- 懒人图库-JS“焦点图”代码 漂亮的图片变化效果
- Exchange 2013SP1和O365混合部署系列一
- 一年中重要的节日列表_外贸干货 | 关于节日祝福与安排
- Bernoulli-Gaussian分布
- 数据挖掘导论——可视化分析实验
- 南方cass计算表面积_CASS在工程中的应用“计算表面积”的方法
- thrift开源项目研究
- 20145312 《信息安全系统设计基础》实验三 实时系统的移植
- springboot 企业微信申请域名验证: 将下载的文件( WW_verify_XXXXXX.txt)上传至填写域名根目录下
- sprint 1 的总结
- vmware 安装 黑群晖
- A*寻路算法,循序渐进,附完整源码
- 卸载electron-builder打包出来的应用,删除用户数据