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的背包.不断的放入物品,当然物品有 ...
随机推荐
- PHP面向对象的三大特征操作——封装、继承、多态(下)
<?php 继承(单继承)特点:一个子类只有一个父类,一个父类可以有多个子类.//父类(基类)class Ren{ public $name; public function say ...
- My97DatePicker 只显示月份
<script src="../javascript/My97DatePicker/WdatePicker.js" type="text/javascript&qu ...
- node.js 环境
Centos 7.2 安装 Node.js 环境 Node.js 是运行在服务端的 JavaScript, 是基于 Chrome JavaScript V8 引擎建立的平台. 1. Node.js w ...
- luogu P4183 [USACO18JAN]Cow at Large P
传送门 首先考虑N^2做法,每次从一个点出发,如果到达一个点,然后到达这个点的时间\(\le\)离这个点最近的叶子距离\(di_x\),那么答案+1,否则继续找点 这个暴力很不好优化.可以这样认为,如 ...
- mysql库文件操作:
增 : create database db1 charset utf8; 查询: 当前创建的库 show create database db1; 所有: show databases; 改 ...
- Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getClassLoader()Ljava/lang/ClassLoader;
运行tomat 报错: Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getClassLoader()Lj ...
- vue 学习笔记—Es6
// 第一部分 /* console.log(a+'c'); var a = 1; console.log(b+'c'); let b =1; */ // 上述代码 left定义报错 原因: /* v ...
- MySql cmd下的学习笔记 —— 有关select的操作(max, min等常见函数)
先把之前建的goods表找到 找到最贵的本店价(max) 找到最便宜的本店价(min) 查出一共还有多少商品(count) 查看商品价的平均价(avg) 查看本店有多少种商品 当count(*)时 输 ...
- C++拷贝构造函数(深拷贝&浅拷贝)
对于普通类型的对象来说,它们之间的复制是很简单的,例如: int a=88; int b=a; 而类对象与普通对象不同,类对象内部结构一般较为复杂,存在各种成员变量.下面看一个类对象拷贝的简单例子. ...
- LwIP Application Developers Manual4---传输层之UDP、TCP
1.前言 本文主要讲解传输层协议UDP TCP 2.UDP 2.1 UDP from an application perspective 2.2 UDP support history in lwI ...