HDU Problem 2062 Bone Collector【01背包】
Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 51847 Accepted Submission(s): 21829
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.
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 1000 + 10; const int INF = 0x3f3f3f3f; int n, v, val[MAXN], vol[MAXN], dp[MAXN][MAXN]; int main() {int t; scanf("%d", &t);while (t--) {scanf("%d %d", &n, &v);for (int i = 0; i < n; i++) {scanf("%d", &val[i]);}for (int i = 0; i < n; i++) {scanf("%d", &vol[i]);}memset(dp, 0, sizeof(dp));for (int i = n - 1; i >= 0; i--) {for (int j = 0; j <= v; j++) {if (j < vol[i]) dp[i][j] = dp[i + 1][j];else dp[i][j] = max(dp[i+1][j], dp[i+1][j-vol[i]]+val[i]);}}printf("%d\n", dp[0][v]);}return 0; }
转载于:https://www.cnblogs.com/cniwoq/p/6770830.html
HDU Problem 2062 Bone Collector【01背包】相关推荐
- hdu 2602 Bone Collector 01背包
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 【HDU - 2639】Bone Collector II (第K大背包,dp,STLset)
题干: The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rookie Cup ...
- hdu 6149 Valley Numer II(01背包套状压dp)
题目链接:hdu 6149 Valley Numer II 题意: 给你N个点,有k个为高点,其他为低点,现在这N个点有m条边,问你最多能组成多少个两个高点一个低点,低点和两个高点都有边相连这样的状态 ...
- hdu 1864 最大报销额01背包dp
最大报销额 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Subm ...
- hdu 2546 饭卡(01背包)
题意:只要最后留下的钱够5元,就可以买下最贵的食物,使得余额最低,其他的钱的使用就是一个最大背包问题了. 代码: #include<iostream> #include<cstrin ...
- HDu 3449 (有依赖的01背包) Consumer
题意: 有n件物品,对应有不同的价格和价值,这是典型的01背包.但现在有了一个限制,要买物品先买能装这件物品的特定的盒子,盒子的价值为0 代码理解得还不是太好,感觉这是一个"二重" ...
- hdu 6092 Rikka with Subset 01背包 思维
dp[i][j]表示前i个元素,子集和为j的个数.d[i][j] = d[i][j] + d[i-1][j-k] (第i个元素的值为k).这里可以优化成一维数组 比如序列为 1 2 3,每一步的dp值 ...
- HDU Bone Collector (01背包问题)
之前背包问题学了忘学了忘= =是太笨了. 题目 许多年前,在泰迪的家乡,有一个人被称为"骨收集者".这个人喜欢收集各种骨头,例如狗,牛的骨头,他也去了坟墓-- 骨头收集者有一个大袋 ...
- hdu 2546 饭卡【01背包】
题目链接:https://vjudge.net/contest/103424#problem/C 饭卡 Time Limit: 5000/ ...
最新文章
- Java绘图之AWT中的继承关系图
- 总结CSS3新特性(媒体查询篇)
- Java会话技术之 —— cookie与session
- jQuery .tmpl(), .template()学习
- 德国黑客使用租用的计算机资源攻击散列算法
- 为JavaScript日期添加天数
- sap 中migo收货自动打印smartform_EWM MES/ERP集成 生产收货的几种方式
- 权限管理----用户与模块关系
- 【合天网安】SQLi-Labs系列之数字型报错注入
- element Table+Pagination实现分页
- 王家林Spark视频
- C#版OPCClient代码总结
- 编程实现在IntAct数据集上批量查找蛋白交互对
- Excel数据可视化——隐藏相同数据
- Android 5.0 CardView 应用
- python更复杂的输出格式
- l05173芯片针脚图_芯片引脚定义
- 手机系统暗潮汹涌 Symbian将何去何从?
- Android:MTK的Dialer模块联系人搜索
- 基于OFDM的水声通信系统设计