Bone Collector(01背包)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/N
题目:
Description
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
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
Sample Input
Sample Output
分析:
将前i件物品放入容量为j的背包中”这个子问题,若只考虑第i件物品的策略(放或不放),那么
就可以转化为一个只牵扯前i-1件物品的问题。如果不放第i件物品,那么问题就转化为“前i-1件
物品放入容量为j的背包中”,价值为f[i-1][j];如果放第i件物品,那么问题就转化为“前i-1件物品放
入剩下的容量为j-v[i]的背包中”,此时能获得的最大价值就是f[i-1][j-v[i]]再加上通过放入第i件物品获得的价值m[i] .
#include<iostream>
#include<cstring>
using namespace std;
int m[],v[];
int f[][];
int max(int a,int b)
{
if(a>b) return a;
else return b;
}
int main()
{
int t,n,i,j,M;
cin>>t;
while(t--)
{
cin>>n>>M;
for(i=;i<=n;i++)
cin>>m[i];
for(i=;i<=n;i++)
cin>>v[i];
for(i=;i<=n;i++)
for(j=;j<=M;j++)
{
f[i][j]=(i==?:f[i-][j]);
if(j>=v[i])
f[i][j]=max(f[i][j],f[i-][j-v[i]]+m[i]);
}
cout<<f[n][M]<<endl;
}
return ;
}
Bone Collector(01背包)的更多相关文章
- Bone Collector(01背包+记忆化搜索)
Bone Collector Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- HDU 2602 Bone Collector(01背包裸题)
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu2602 Bone Collector 01背包
Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like ...
- HDU 2602 - Bone Collector - [01背包模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a ...
- [原]hdu2602 Bone Collector (01背包)
本文出自:http://blog.csdn.net/svitter 题意:典型到不能再典型的01背包.给了我一遍AC的快感. //=================================== ...
- hdu2602 Bone Collector (01背包)
本文来源于:http://blog.csdn.net/svitter 题意:典型到不能再典型的01背包.给了我一遍AC的快感. //================================== ...
- HDU 2602 Bone Collector --01背包
这种01背包的裸题,本来是不想写解题报告的.但是鉴于还没写过背包的解题报告.于是来一发. 这个真的是裸的01背包. 代码: #include <iostream> #include < ...
- ACM HDU Bone Collector 01背包
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 这是做的第一道01背包的题目.题目的大意是有n个物品,体积为v的背包.不断的放入物品,当然物品有 ...
- 解题报告:hdu2602 Bone collector 01背包模板
2017-09-03 15:42:20 writer:pprp 01背包裸题,直接用一维阵列的做法就可以了 /* @theme: 01 背包问题 - 一维阵列 hdu 2602 @writer:ppr ...
- HDU 2602 Bone Collector (01背包DP)
题意:给定一个体积,和一些物品的价值和体积,问你最大的价值. 析:最基础的01背包,dp[i] 表示体积 i 时最大价值. 代码如下: #pragma comment(linker, "/S ...
随机推荐
- PMP 第十二章 项目采购管理
1规划采购 2实施采购 3管理采购 4结束采购 1.合同的不同叫法?卖方的不同叫法? 2.规划采购管理的目的是什么?合同类型有哪些?不同的特点是什么?何种情况下应选择何种合同?自制或外购分析计算和合同 ...
- apk 打包方式
1 项目-->Android tools -->Export Signed Application Package 2 在项目 manifest.xml文件下 单击“use the Ex ...
- php 常见的问题
1. this指针错误的引用变量($(php)<->*(c)) $this->inputData right wrong 2. json_encode(array) 不一定按数组关键 ...
- hdu2191 多重背包
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2191 多重背包:有N种物品和一个容量为V的背包.第i种物品最多有n[i]件可用,每件费用是 ...
- http://www.blogjava.net/zhangchao/archive/2011/05/26/351051.html
http://www.blogjava.net/zhangchao/archive/2011/05/26/351051.html
- SQL SERVER 和ACCESS的数据导入导出
//批量导入Access string filepath = Server.MapPath("student.mdb"); stri ...
- [转]error while loading shared libraries 错误解决办法总结
http://blog.csdn.net/wallwind/article/details/7580659 错误信息: error while loading shared libraries: li ...
- Python for Informatics 第11章 正则表达式一(译)
注:文章原文为Dr. Charles Severance 的 <Python for Informatics>.文中代码用3.4版改写,并在本机测试通过. 目前为止,我们一直在通读文件,查 ...
- Android 模糊效果
(1)FastBlur http://www.cnblogs.com/CharlesGrant/p/4813735.html (2)StackBlur 基于RenderScript,StackBlur ...
- Android自动化测试框架
1.Monkeyrunner:优点:操作最为简单,可以录制测试脚本,可视化操作:缺点:主要生成坐标的自动化操作,移植性不强,功能最为局限: 2.Rubotium:主要针对某一个APK进行自动化测 ...