HDU2602(01背包)
Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 44257 Accepted Submission(s): 18442
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.
/*
Accepted 2602 78MS 5360K 552 B G++
*/
#include"cstdio"
#include"cstring"
#include"algorithm"
using namespace std;
const int MAXN=;
int dp[MAXN][MAXN];
int n,W;
int v[MAXN],w[MAXN];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&W);
memset(dp,,sizeof(dp));
for(int i=;i<n;i++) scanf("%d",&v[i]);
for(int i=;i<n;i++) scanf("%d",&w[i]); for(int i=;i<n;i++)
for(int j=;j<=W;j++)
if(j<w[i]) dp[i+][j]=dp[i][j];
else dp[i+][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]); printf("%d\n",dp[n][W]);
} return ;
}
贴一个记忆化搜索
/*
Accepted 2602 327MS 5432K 613 B G++
*/
#include"cstdio"
#include"cstring"
#include"algorithm"
using namespace std;
const int MAXN=;
int dp[MAXN][MAXN];
int n,W;
int v[MAXN],w[MAXN];
int dfs(int i,int wei)
{
if(dp[i][wei]) return dp[i][wei];
if(i==n) return ;
int res;
if(wei>=w[i]) res=max(dfs(i+,wei-w[i])+v[i],dfs(i+,wei));
else res=dfs(i+,wei);
return dp[i][wei]=res;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&W);
memset(dp,,sizeof(dp));
for(int i=;i<n;i++) scanf("%d",&v[i]);
for(int i=;i<n;i++) scanf("%d",&w[i]);
printf("%d\n",dfs(,W));
} return ;
}
HDU2602(01背包)的更多相关文章
- HDU2602 Bone Collector(01背包)
HDU2602 Bone Collector 01背包模板题 #include<stdio.h> #include<math.h> #include<string.h&g ...
- [原]hdu2602 Bone Collector (01背包)
本文出自:http://blog.csdn.net/svitter 题意:典型到不能再典型的01背包.给了我一遍AC的快感. //=================================== ...
- HDU2602 Bone Collector 【01背包】
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 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 ...
- 01背包模板题 hdu2602 Bonecollector
由于数组的滚动过程中当前值(i,j)的更新需要用到上一层的(i-1,j-wi)的值,所以在更新当前的j之前不能更新上一层的j之前的值,故01背包是从后向前更新的(重量取值是从大到小的). 代码如下: ...
- hdu-2602&&POJ-3624---01背包裸题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 https://vjudge.net/problem/POJ-3624 都是01背包的裸题 这 ...
- HDU 2639(01背包求第K大值)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2639 Bone Collector II Time Limit: 5000/2000 MS (Jav ...
- UVALive 4870 Roller Coaster --01背包
题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F , D -= K 问在D小于等于一定限度的时 ...
随机推荐
- C中的预编译编译链接
http://ke.qq.com/webcourse/index.html#course_id=67888&term_id=100058920&taid=13934591901 ...
- cocosStudio中使用PageView,ListView和ScrollView
晚上吃东西好像吃坏肚子了,.但是技术还要继续研究.最近工作中要使用CocosStudio做界面,好吧,不管对他有什么偏见,学习一下吧.这里主要记录一下三个控件的使用和说明.就是ScrollView,L ...
- 储存技术(SLC、MLC、TLC和QLC的NAND闪存技术)和Optane Memory
1.转载:Optane Memory 2.构成SSD的主要IC有主控芯片和NAND闪存,SLC.MLC和TLC三者都是闪存的类型 需要说明的闪存的寿命指的是写入(擦写)的次数,不是读出的次数,因为读取 ...
- 一起学android之怎样卸载指定的 应用程序(25)
效果图例如以下: 代码例如以下: public class MainActivity extends Activity { private Button btn_delete; @Override p ...
- 【windows phone】CollectionViewSource的妙用
在windows phone中绑定集合数据的时候,有时候需要分层数据,通常需要以主从试图形式显示.通常的方法是将第二个ListBox(主视图)的数据源绑定到第一个ListBox (从视图)的Selec ...
- Spring中的面向切面编程(AOP)简介
一.什么是AOP AOP(Aspect-Oriented Programming, 面向切面编程): 是一种新的方法论, 是对传统 OOP(Object-Oriented Programming, 面 ...
- vmware安装操作系统
安装的时候,直接选择“从光盘或者映像安装”就可以了,很方便的.不需要再去从u盘什么的安装了.
- wepy开发
工欲善其事必先利其器 ide安装.配置] https://tencent.github.io/wepy/document.html VS Code 1. 在 Code 里先安装 Vue 的语法高亮 ...
- 今日头条Go建千亿级微服务的实践
今日头条Go建千亿级微服务的实践_36氪 http://36kr.com/p/5073181.html
- Memory usage of a Java process java Xms Xmx Xmn
http://www.oracle.com/technetwork/java/javase/memleaks-137499.html 3.1 Meaning of OutOfMemoryError O ...