Bone Collector

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

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
 
Sample Output
14
 
Author
Teddy
 
Source
 
Recommend
lcy

这道题,我学会了,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(背包问题,模版)的更多相关文章

  1. HDU 2602 Bone Collector 0/1背包

    题目链接:pid=2602">HDU 2602 Bone Collector Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...

  2. HDOJ(HDU).2602 Bone Collector (DP 01背包)

    HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...

  3. HDU 2602 Bone Collector(经典01背包问题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/O ...

  4. HDU 2602 Bone Collector (01背包问题)

    原题代号:HDU 2602 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 原题描述: Problem Description Many yea ...

  5. hdu 2602 Bone Collector(01背包)模板

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...

  6. HDU 2602 Bone Collector

    http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...

  7. HDU 2602 Bone Collector (简单01背包)

    Bone Collector http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , i ...

  8. hdu 2602 Bone Collector 背包入门题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 题目分析:0-1背包  注意dp数组的清空, 二维转化为一维后的公式变化 /*Bone Coll ...

  9. HDU 2602 Bone Collector(01背包裸题)

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

随机推荐

  1. boke练习: category类的编辑修改,总是提示:该分类名称已经存在

    boke练习: category类的编辑修改,总是提示:该分类名称已经存在 本利采用的dao是: jpaRepository方式 先看原始代码: category的实体类 @Entity public ...

  2. android -------- java虚拟机和Dalvik虚拟机

    java虚拟机 虚拟机是一种抽象化的计算机,通过在实际的计算机上仿真模拟各种计算机功能来实现的.Java虚拟机有自己完善的硬体架构,如处理器.堆栈.寄存器等,还具有相应的指令系统.Java虚拟机屏蔽了 ...

  3. 正睿 2018 提高组十连测 Day4 T3 碳

    记'1'为+1,'0'为-1; 可以发现 pre[i],suf[i]分别为前/后缀和 a[i]=max(pre[l.....i]); b[i]=max(suf[i+1....r]); ans=max( ...

  4. python记录_day13 内置函数

    详细链接:https://www.processon.com/mindmap/5bdbc4bee4b0878bf42089fb

  5. oracle 基本操作--事务

    事务:可以看做是由对数据可的若干操作组成的一个单元,浙西操作要么都完成,要么都取消,从而保证数据满足一致性的要求. 事务的组成: 一条或者多条DML 一条DDL 一条DCL DML语句需要使用comm ...

  6. MSMQ消息传递的优先级

    一.消息传递的优先级 在MSMQ中消息在队列里传输是分有优先级的,这里我就以实例的形式介绍下关于优先级的使用,优先级一共有七种,MessagePriority枚举里全部进行了封装.因这里只作程序演示就 ...

  7. MySQL安装脚本最佳实践

    MySQL安装脚本最佳实践 2018年9月19日 17:01 #!/bin/bash   export host_ip=192.168.7.206   echo '#1.取master主机ip的后三位 ...

  8. Leetcode 129

    /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...

  9. SecureCRT sftp上传文件报错:put: failed to upload xxx 拒绝访问

    1.问题 使用sftp上传文件时报错:put: failed to upload xxx 拒绝访问.类似下图所示: 2.原因 造成这个问题的原因可能有两个,一是要上到的那个目录剩余磁盘空间不足,二是打 ...

  10. Generative Model 与 Discriminative Model

      [摘要]    - 生成模型(Generative Model) :无穷样本==>概率密度模型 = 产生模型==>预测    - 判别模型(Discriminative Model): ...