Bone Collector

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 44257    Accepted Submission(s): 18442

Problem Description
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 ?
Input
The first line contain a integer T , the number of cases.
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
One integer per line representing the maximum of the total value (this number will be less than 231).
 
Sample Input
1
5 10
1 2 3 4 5
5 4 3 2 1
 
01背包模板题
/*
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背包)的更多相关文章

  1. HDU2602 Bone Collector(01背包)

    HDU2602 Bone Collector 01背包模板题 #include<stdio.h> #include<math.h> #include<string.h&g ...

  2. [原]hdu2602 Bone Collector (01背包)

    本文出自:http://blog.csdn.net/svitter 题意:典型到不能再典型的01背包.给了我一遍AC的快感. //=================================== ...

  3. HDU2602 Bone Collector 【01背包】

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  4. hdu2602 Bone Collector (01背包)

    本文来源于:http://blog.csdn.net/svitter 题意:典型到不能再典型的01背包.给了我一遍AC的快感. //================================== ...

  5. 解题报告:hdu2602 Bone collector 01背包模板

    2017-09-03 15:42:20 writer:pprp 01背包裸题,直接用一维阵列的做法就可以了 /* @theme: 01 背包问题 - 一维阵列 hdu 2602 @writer:ppr ...

  6. 01背包模板题 hdu2602 Bonecollector

    由于数组的滚动过程中当前值(i,j)的更新需要用到上一层的(i-1,j-wi)的值,所以在更新当前的j之前不能更新上一层的j之前的值,故01背包是从后向前更新的(重量取值是从大到小的). 代码如下: ...

  7. hdu-2602&&POJ-3624---01背包裸题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 https://vjudge.net/problem/POJ-3624 都是01背包的裸题 这 ...

  8. HDU 2639(01背包求第K大值)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2639 Bone Collector II Time Limit: 5000/2000 MS (Jav ...

  9. UVALive 4870 Roller Coaster --01背包

    题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F ,     D -= K 问在D小于等于一定限度的时 ...

随机推荐

  1. 百科知识 kux文件如何打开

    即使是官方自带的浏览器也无法打开   你可以直接复制文件名   然后在百度里搜即可   你自己下载的东西还是能转码的      

  2. java性能监控工具jstat-windows

    jstat Monitors Java Virtual Machine (JVM) statistics. This command is experimental and unsupported. ...

  3. 怎样把多个Android Project打包成一个APK

    怎样把多个Android Project打包成一个APK(你的项目怎样引用其它项目). 怎样把多个android project 打包成一个apk呢,事实上原理是这种.一个主project引用其它的p ...

  4. 常见Struts、Hibernate、Spring、J2EE、ibatis、Oracle等开发框架架构图及其简介

    各种系统架构图及其简介 转载请保留出处,不胜人生一场醉汇总. 以下文字和架构图均在本人相关系统设计和架构方案中有所应用. 原文出处:http://space.itpub.net/6517/viewsp ...

  5. PHP中curl获取本机虚拟主机接口

    在PHP的curl代码中增加header可解决此问题. $header = array( "Host: 你的域名(不能包含http://)", "Accept: text ...

  6. 福昕熊雨前:PDFium开源项目的背后

    今天编译android的时候,无意中看到命令行提示出输出编译external/pdfium这个目录,于是乎上百度搜索了一下,找到了如下关于PDF文件解析的开源代码的文章: http://www.csd ...

  7. 服务管理-Nginx

    nginx优势 select,epoll模型 对于一次IO访问(以read举例),数据会先被拷贝到操作系统内核的缓冲区中,然后才会从操作系统内核的缓冲区拷贝到应用程序的地址空间.所以说.当一个read ...

  8. linux命令详解:file命令

    前言 file命令可以获取多种文件类型,包括文本文件.脚本文件.源码文件.多媒体文件(音频视频)等.file是通过查看文件的头部内容,来获取文件的类型,而不像Window那样是通过扩展名来确定文件类型 ...

  9. EF架构~终于自己架构了一个相对完整的EF方案

    EF4.1学了有段时间了,没有静下来好好研究它的架构,今天有空正好把它的架构及数据操作这段拿出来,希望给大家带来帮助,对我自己也是一种总结:P 从图中可以看到,我们用的是MVC3进行程序开发的,哈哈, ...

  10. 用Cocoapods集成XMPPFramework 遇 Module 'KissXML' not found 问题

    用Coacopods集成XMPPFramework完成后Command + B,报Module 'KissXML' not found 一般来说,通过Coacopods集成集成第三方框架,不会再有依赖 ...