HDU 2602 Bone Collectors(背包问题,模版)
Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 14336 Accepted Submission(s): 5688
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.
这道题,我学会了,dp数组一定要放在主函数的外面,不然编译器就会崩!!!
这里的j起始要从0开始,这是十分恶心的地方,肯能就是volume=0也会有value!!!这个是个巨型的坑!!!!!
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int dp[][];
int main()
{
int t;
cin>>t;
int n,m;
int w[],v[];
int f1,f2;
while(t--)
{
cin>>n>>m;
memset(w,,sizeof(w));
memset(v,,sizeof(v));
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
{
cin>>v[i];
}
for(int i=;i<=n;i++)
{
cin>>w[i];
}
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(j<w[i]) dp[i][j]=dp[i-][j];
else
{
f1=i;
f2=j;
dp[i][j]=max(dp[i-][j],dp[i-][j-w[i]]+v[i]);
}
}
}
cout<<dp[f1][f2]<<endl;
}
return ;
}
HDU 2602 Bone Collectors(背包问题,模版)的更多相关文章
- HDU 2602 Bone Collector 0/1背包
题目链接:pid=2602">HDU 2602 Bone Collector Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...
- HDOJ(HDU).2602 Bone Collector (DP 01背包)
HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...
- HDU 2602 Bone Collector(经典01背包问题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/O ...
- HDU 2602 Bone Collector (01背包问题)
原题代号:HDU 2602 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 原题描述: Problem Description Many yea ...
- 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
http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 2602 Bone Collector (简单01背包)
Bone Collector http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , i ...
- hdu 2602 Bone Collector 背包入门题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 题目分析:0-1背包 注意dp数组的清空, 二维转化为一维后的公式变化 /*Bone Coll ...
- HDU 2602 Bone Collector(01背包裸题)
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
随机推荐
- 怎么从bam文件中提取出比对OR没比对上的paired reads | bamToFastq | STAR
折腾这么多都是白瞎,STAR就有输出没有别对上的pair-end reads的功能 参见:How To Filter Mapped Reads With Samtools I had the same ...
- English trip V1 - 9.Do you Ever Say Never? 你有没有说永远不会? Teacher:Lamb Key: Adverbs of frequency (频率副词)
In this lesson you will learn to describe what you do at home. 在本课中,您将学习如何描述您在家中所做的事情. 课上内容(Lesson) ...
- MySQL的自动补全和语法高亮工具MyCli
官方地址: RHEL, Centos: We don't have packages for RHEL or Centos, yet. Instead, use pip to install mycl ...
- Javascript的常见数据类型以及相应操作
JavaScript概述 1 ECMAScript和JavaScript的关系 1996年11月,JavaScript的创造者--Netscape公司,决定将JavaScript提交给国际标准化组织E ...
- shiro中INI配置
4.1 根对象SecurityManager 从之前的Shiro架构图可以看出,Shiro是从根对象SecurityManager进行身份验证和授权的:也就是所有操作都是自它开始的,这个对象是线程安全 ...
- kolla-ansible 一键安装openstack
官网地址https://docs.openstack.org/kolla-ansible/latest/user/quickstart.html 参考:https://www.jianshu.com/ ...
- jq post
var source=[]; $.ajax({ type: "post", url: "connectdb/select.jsp", data: {databa ...
- HttpClient4 警告: Invalid cookie header 的问题解决(转)
原文地址:HttpClient4 警告: Invalid cookie header 的问题解决 最近使用HttpClient4的时候出现如下警告信息 org.apache.http.client.p ...
- CM+CDH安装教程(CentOS)
一.简单介绍 CM:Cloudera Manager,Cloudera公司编写的一个CDH的管理后台,类似各CMS的管理后台. CDH:Cloudera’s distribution,includin ...
- Nginx隐藏版本号操作
1.定位当前nginx所使用的配置文件 ps -ef |grep nginx 如果-c参数.则-c文件即为nginx当前所用配置文件,如上图中配置文件即为/usr/local/nginx/conf/n ...