hdu2602 Bone Collector(01背包) 2016-05-24 15:37 57人阅读 评论(0) 收藏
Bone Collector
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.
1
5 10
1 2 3 4 5
5 4 3 2 1
14
若容量不够不能取,则dp[i][j]=dp[i][j-1];
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int dp[1005][1005];
int main()
{
int weight[1005],val[1005],sum,n,o;
while(~scanf("%d",&o))
{
while(o--)
{
scanf(" %d %d",&n,&sum);
for(int i=1;i<=n;i++)
scanf("%d",&val[i]);
for(int i=1;i<=n;i++)
scanf("%d",&weight[i]);
memset(dp,0,sizeof(dp));
for(int i=0;i<=sum;i++)
for(int j=1;j<=n;j++)
{
if(dp[i][j]+weight[j]<=i)
dp[i][j]=max(dp[i][j-1],dp[i-weight[j]][j-1]+val[j]);
else
dp[i][j]=dp[i][j-1];
}
printf("%d\n",dp[sum][n]); }
}
return 0;
}
hdu2602 Bone Collector(01背包) 2016-05-24 15:37 57人阅读 评论(0) 收藏的更多相关文章
- hdu2602 Bone Collector 01背包
Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like ...
- [原]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 ...
- NYOJ-289 苹果 289 AC(01背包) 分类: NYOJ 2014-01-01 21:30 178人阅读 评论(0) 收藏
#include<stdio.h> #include<string.h> #define max(x,y) x>y?x:y struct apple { int c; i ...
- HDU-2602 Bone Collector——01背包
首先输入一个数字代表有n个样例 接下来的三行 第一行输入n 和 v,代表n块骨头,背包体积容量为v. 第二行输入n块骨头的价值 第三行输入n块骨头的体积 问可获得最大的价值为多少 核心:关键在于d ...
- hdu1171 Big Event in HDU(01背包) 2016-05-28 16:32 75人阅读 评论(0) 收藏
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 【C#小知识】C#中一些易混淆概念总结(二)--------构造函数,this关键字,部分类,枚举 分类: C# 2014-02-03 01:24 1576人阅读 评论(0) 收藏
目录: [C#小知识]C#中一些易混淆概念总结--------数据类型存储位置,方法调用,out和ref参数的使用 继上篇对一些C#概念问题进行细节的剖析以后,收获颇多.以前,读书的时候,一句话一掠而 ...
- Hardwood Species 分类: POJ 树 2015-08-05 16:24 2人阅读 评论(0) 收藏
Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 20619 Accepted: 8083 De ...
随机推荐
- websoket
http://blog.csdn.net/xueling022/article/details/52902358
- conductor Workflow Metrics
Server Metrics conductor使用spectator收集指标.https://github.com/Netflix/spectator 名称 目的 标签 workflow_serve ...
- Spring AsyncRestTemplate
类说明 AsyncRestTemplate 是 Spring中提供异步的客户端HTTP访问的核心类.与RestTemplate类相似,它提供了一些类似的方法,只不过返回类型不是具体的结果,而是List ...
- Maven项目整合SSH框架
---------------------siwuxie095 Maven 项目整合 SSH 框架 创建 ...
- Java SE-基本数据类型对应包装类
包装类 Java是面向对象的编程语言,包装类的出现更好的体现这一思想. 其次,包装类作为类是有属性有方法的,功能比基本数据类型要强大. [八种基本数据类型的包装类] byte ——Byte short ...
- VC2008 类型重定义的问题
Q: 比如"a.h"里定义了类a,类a所有函数的实现都放在"a.cpp"里.然后"b.h"和"c.h"都需要用到类a,所 ...
- vue-awesome-swiper插件
http://www.cnblogs.com/songrimin/p/6905136.html 这个地址不错 在上一些我的demo代码 第一步安装 npm install vue-awesome-sw ...
- Linux screen命令
一.简介 GNU Screen是一款由GNU计划开发的用于命令行终端切换的自由软件.用户可以通过该软件同时连接多个本地或远程的命令行会话,并在其间自由切换. GNU Screen可以看作是窗口管理器的 ...
- 品味性能之道<六>:图形化SQL分析工具
在上一章里,重点分享了命令行SQL分析工具的使用方法.在本章将重点分享PL/SQL的SQL分析工具. 一.如何打开PL/SQL执行计划 开启PL/SQL这工具,推荐如下方法: 点击 ...
- apache的80端口被占用
1.netstart -ano | findstr "80":查看80端口是否被占用,并找出对应的pid 2.关掉pid对应的进程