HDU 2602 Bone Collector DP(01背包)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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
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
Sample Input
1 5 10 1 2 3 4 5 5 4 3 2 1
Sample Output
14 很基础的一道dp熟悉一下
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w",stdout);
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long LL;const int MAXN=1005;
int dp[MAXN][MAXN];
int value[MAXN];
int volume[MAXN];int main()
{//FINint T;scanf("%d",&T);while(T--){int n,v;scanf("%d%d",&n,&v);for(int i=1;i<=n;i++)scanf("%d",&value[i]);for(int i=1;i<=n;i++)scanf("%d",&volume[i]);memset(dp,0,sizeof(dp));for(int i=1;i<=n;i++)for(int j=0;j<=v;j++){if(j>=volume[i])dp[i][j]=max(dp[i-1][j],dp[i-1][j-volume[i]]+value[i]);elsedp[i][j]=dp[i-1][j];}printf("%d\n",dp[n][v]);}}
转载于:https://www.cnblogs.com/Hyouka/p/5730984.html
HDU 2602 Bone Collector DP(01背包)相关推荐
- 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背包)
题意:给出包裹的大小v,然后给出n块骨头的价值value和体积volume,求出一路下来包裹可以携带骨头最大价值 思路:01背包 1.二维数组(不常用 #include<iostream> ...
- HD 2602 Bone Collector (0-1背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , in Teddy's ...
- hdu 2602 Bone Collector 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 在没学01背包时做的,很遗憾的是,wa了很多次. wa代码 1 #include <ios ...
- hdu 2602 Bone Collector 01背包
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU Problem 2062 Bone Collector【01背包】
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- Bone Collector【01背包】
F - Bone Collector HDU - 2602 Many years ago , in Teddy's hometown there was a man who was called &q ...
- hdu 2602 Bone Collector
终于开始做自己一直不敢碰的dp了,内心颇不平静.很久以前看过的背包九讲也没什么印象了.这个题错了四次.之前老师有说过看到dp不要把它想成dp,要按照数学归纳的路子来.先来个最初的归纳假设,如果过弱再加 ...
- HDU 2602 Bone Collector - from lanshui_Yang
题目大意:有n件物品,每件物品均有各自的价值和体积,给你一个容量为 V 的背包,问这个背包最多能装的物品的价值是多少? 解题思路:这是一道0 - 1 背包的简单模板题,也是 ...
最新文章
- 利用ListView实现新闻客户端的新闻内容图文混排
- Hadoop HDFS概念学习系列之熟练掌握HDFS的Shell访问(十五)
- HEX、DEC、OCT和BIN的解释
- PHP的display_errors与error_reporting
- android 6关闭防火墙,安卓手机如何关闭防火墙
- opencv2.4.9报错找不到opencv_video249d.dll
- linux c设置系统时间函数,Linux C 中获取local日期和时间 time()localtime()函数
- 简述中断处理的6个步骤_基于SCDM软件的CFD前处理工作5个步骤
- lj245a引脚功能图_CA3140中文资料-引脚图及功能
- 以编程方式使用 Microsoft Office Visio 2003 ActiveX 控件
- Could Not find resource [logback.groovy] ; Cound Not find resource [logback-test.xml]
- 微信小程序授权微信开放平台
- 如何退出或卸载奇安信天擎软件
- 坚持住啊,还在代码屎山中爬行的同事们
- go mod invalid pseudo-version
- 「Computer keyboard」- 在键盘中,手指的摆放位置 @20210331
- Win10 无法使用内置管理员账户打开应用程序解决方案
- 一文了解无聊猿(BAYC)的 NFT 帝国是如何形成的
- L2-3 清点代码库 (25 分)
- 请问这个动态表格的表单内容如何写才能存入ACCess数据库中