hdu2602 Bone Collector 01背包
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 ?

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 <bits/stdc++.h> using namespace std;
int t,n,m,v[],w[],i,j,f[][];
int main()
{
cin>>t;
while(t--){
cin>>n>>m;
for(i=;i<=n;i++) cin>>v[i];
for(i=;i<=n;i++) cin>>w[i];
memset(f,,sizeof(f));
for(i=;i<=n;i++) //装入第i个骨头时,背包容量为j时的最大价值
for(j=;j<=m;j++){
if(j<w[i]){
f[i][j]=f[i-][j];
}
else{
f[i][j]=max(f[i-][j],f[i-][j-w[i]]+v[i]);
}
}
cout<<f[n][m]<<endl;
}
return ;
}
#include <bits/stdc++.h> using namespace std;
int n,m,f[],v[],w[],i,j,t; int main()
{
cin>>t;
while(t--){
cin>>n>>m;
for(i=;i<=n;i++) cin>>v[i];
for(i=;i<=n;i++) cin>>w[i];
memset(f,,sizeof(f));
for(i=;i<=n;i++)
for(j=m;j>=w[i];j--){
if(f[j]<f[j-w[i]]+v[i])
f[j]=f[j-w[i]]+v[i];
}
cout<<f[m]<<endl;
}
return ;
}
hdu2602 Bone Collector 01背包的更多相关文章
- [原]hdu2602 Bone Collector (01背包)
本文出自:http://blog.csdn.net/svitter 题意:典型到不能再典型的01背包.给了我一遍AC的快感. //=================================== ...
- hdu2602 Bone Collector (01背包)
本文来源于:http://blog.csdn.net/svitter 题意:典型到不能再典型的01背包.给了我一遍AC的快感. //================================== ...
- 解题报告:hdu2602 Bone collector 01背包模板
2017-09-03 15:42:20 writer:pprp 01背包裸题,直接用一维阵列的做法就可以了 /* @theme: 01 背包问题 - 一维阵列 hdu 2602 @writer:ppr ...
- HDU-2602 Bone Collector——01背包
首先输入一个数字代表有n个样例 接下来的三行 第一行输入n 和 v,代表n块骨头,背包体积容量为v. 第二行输入n块骨头的价值 第三行输入n块骨头的体积 问可获得最大的价值为多少 核心:关键在于d ...
- 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 ...
- HDU 2602 - Bone Collector - [01背包模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a ...
- 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的背包.不断的放入物品,当然物品有 ...
随机推荐
- 哪些领域适合开发微信小程序
什么是小程序?小程序的实质就是webapp,最典型的案例是接入微信的“滴滴打车”.虽然没有下载安装APP,但通过微信完全可以正常使用滴滴打车的服务,需要的定位.支付等底层能力,微信都可以提供. 张小龙 ...
- Leetcode#709. To Lower Case(转换成小写字母)
题目描述 实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串. 示例 1: 输入: "Hello" ...
- delegate事件委托
下面举个例子 我们希望通过点击使得点击的li标签变红 <body style="height:2000px;"> <ul> <li>1111&l ...
- Thymeleaf--:fragment
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" ...
- 20165234 《Java程序设计》第三周学习总结
第三周学习总结 教材学习内容总结 第四章 编程语言的几个发展阶段: 面向机器语言 面向过程语言 面向对象语言 类 1. 类声明: class People { ... } class 动物 { ... ...
- 20165337第七周实验报告《Java面向对象程序设计》
实验报告封面 实验内容及步骤 实验一.实现百分制成绩转成"优.良.中.及格.不及格"五级制成绩的功能 代码 public class MyUtil{ public static S ...
- 图片转换base64编码,点击div的时候选择文件
有时候我们希望文件上传的时候预览图片,下面插件可以实现上传前预览图片 (也可以提取文件的base64编码) max-height: 140px;max-width: 120px;可以指定图片的最大宽度 ...
- linux 安装图行界面
centos6的环境中 代码:[root@ebs122 sysconfig]#yum groupinstall "Desktop" 使用 init 5命令进入图形化界面,如果成功的 ...
- SQL 删除的三个语句:DROP、TRUNCATE、 DELETE 的区别
转载:http://www.runoob.com/sql/sql-delete.html DROP: DROP test; 删除表test,并释放空间,将test删除的一干二净. TRUNCATE: ...
- 阿里云ECS CentOS 7 安装图形化桌面
CentOS 7 系统下,本文以 MATE 桌面环境安装进行安装配置说明: 1 . 安装 X Window System. yum groups install "X Window Syst ...