hdu 2602 - Bone Collector(01背包)解题报告
Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 39532 Accepted Submission(s): 16385
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 ?
![](http://acm.hdu.edu.cn/data/images/C154-1003-1.jpg)
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.
1
5 10
1 2 3 4 5
5 4 3 2 1
14
题解:
裸的01背包,经典例题。
參考代码:
#include<stdio.h>
#define M 1111
#include<string.h>
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int t,a[M],b[M],dp[M];
scanf("%d",&t);
while(t--)
{
int n,v;
memset(dp,0,sizeof(dp));
scanf("%d%d",&n,&v);
for(int i=0;i<n;i++)
scanf("%d",&b[i]);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=0;i<n;i++)
{
for(int j=v;j>=a[i];j--)
{
dp[j]=max(dp[j],dp[j-a[i]]+b[i]);
}
}
printf("%d\n",dp[v]);
}
return 0;
}
hdu 2602 - Bone Collector(01背包)解题报告的更多相关文章
- 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 < ...
- HDU 2602 Bone Collector (01背包DP)
题意:给定一个体积,和一些物品的价值和体积,问你最大的价值. 析:最基础的01背包,dp[i] 表示体积 i 时最大价值. 代码如下: #pragma comment(linker, "/S ...
- [HDU 2602]Bone Collector ( 0-1背包水题 )
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 水题啊水题 还给我WA了好多次 因为我在j<w[i]的时候状态没有下传.. #includ ...
- HDU 2602 Bone Collector (01背包问题)
原题代号:HDU 2602 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 原题描述: Problem Description Many yea ...
- HDOJ(HDU).2602 Bone Collector (DP 01背包)
HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...
- HDU 2602 Bone Collector 0/1背包
题目链接:pid=2602">HDU 2602 Bone Collector Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 2602 Bone Collector(01背包)模板
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 2602 Bone Collector(经典01背包问题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/O ...
随机推荐
- http content-type总结
content-type 媒体类型,即MIME类型,包括媒体格式和编码两部分 例如:Content-Type:text/html;charset:utf-8 常见的媒体格式类型如下: text/htm ...
- [Linux]方便openmp等程序的类似编译
因为总是打参数例如-fopenmp或者-lGL等等有些麻烦,所以特地写一个可以使用的bash文件用来执行简单的操作 首先在.profile中添加 if [ -d "$HOME/bin&quo ...
- vue.js单文件组件中非父子组件的传值
最近在研究vue.js,总体来说还算可以,但是在web开发群里有一些人问在单文件组件开发模式中非父子组件如何传值的问题,今天在这里讲讲,希望对大家有所帮助! 在官网api中的这段讲解很少,也很模糊:官 ...
- python(5)-- 函数
python 函数 定义:函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 使用好处:函数能提高应用的模块性,和代码的重复利用率. 分类:(1)python 内建函数:pytho ...
- Adreno Profiler分析任意安卓游戏特效+抓取资源
听说可以抓去任意游戏特效..保存下,有空研究 AdrenoProfiler 下载地址 Adreno Profiler分析任意安卓游戏特效+抓取资源 教程
- Docker Daemon 连接方式详解
前言 在 Docker 常用详解指令 一文中粗粗提了一下, Docker 是分为客户端和服务端两部分的, 本文将介绍客户端是如何连接服务端的. 连接方式 1. UNIX域套接字 默认就是这种方式, 会 ...
- How Many to Be Happy?
How Many to Be Happy? 时间限制: 1 Sec 内存限制: 128 MB 题目描述 Let G be a connected simple undirected graph wh ...
- c#调用 WinRAR.exe以命令行形式实现文件、文件夹的解压缩
在实际项目应用中会偶尔使用文件的压缩上传以及服务器端的加压处理,故写此文记录以备不时之需. 1.自己编写的ZipHelper类. public static class ZipHelper { pri ...
- CF 148D Bag of mice【概率DP】
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes Promblem descriptio ...
- TCP/IP和HTTP协议与Socket的区别联系
参考资料: http://www.cnblogs.com/goodcandle/archive/2005/12/10/socket.html http://www.2cto.com/net/20121 ...