Bone Collector HDU 2602 DP 01 背包

原创 2018年04月17日 21:00:29

Bone Collector

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


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

01背包啥都没改,不解释了。。。。

代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;

int n, t, v,  dp[maxn], vaule[maxn], volume[maxn];

int main()
{
    scanf("%d", &t);
    while(t--) {
     scanf("%d%d", &n, &v);
     for(int i = 0; i < n; i++) scanf("%d", &vaule[i]);
     for(int i = 0; i < n; i++) scanf("%d", &volume[i]);
     memset(dp, 0, sizeof(dp));
     int maxl = 0;
     for(int i = 0; i < n; i++)
        for(int j = v; j >= volume[i]; j--) {
            dp[j] = max(dp[j], (dp[j - volume[i]] + vaule[i]));
            maxl = max(dp[j], maxl);
        }
    printf("%d\n", maxl);
    }
    return 0;
}

 
版权声明: https://blog.csdn.net/weixin_39792252/article/details/79980614

hdu2602 Bone Collector (01背包裸题)

分析:经典的01背包题,给出了石头的数量与背包的容量,然后分别给出每个石头的容量与价值,要求最优解,可以说是01背包果题。 题目:http://acm.hdu.edu.cn/showproblem...
  • f1024042400
  • f1024042400
  • 2014-12-25 19:14:02
  • 309

HDU-2602 Bone Collector 【01背包裸题】

Bone CollectorTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T...
  • DTL66
  • DTL66
  • 2016-08-09 20:21:40
  • 147

ACM 杭电hdu 2602 Bone Collector(01背包)

Bone Collector Problem Description Many years ago , in Teddy’s hometown there was a man who was c...
  • someday7_toi
  • someday7_toi
  • 2012-07-24 17:02:32
  • 5698

HDU - 2602 Bone Collector解题报告

背包问题第一道
  • qq_36306833
  • qq_36306833
  • 2017-01-31 23:40:57
  • 402

杭电ACM 2602 Bone Collector背包

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...
  • shellhard
  • shellhard
  • 2017-03-14 23:13:28
  • 398

01背包的理解,二维数组化一维数组的理解(附hdu2602 Bone Collector)

01背包问题:有n个物品和一个容量为v的背包,用val[i]表示第i个物品的价值,用vol[i]表示第i个物品的体积,那么,如何使背包里装的物品的总价值最大呢?贪心是不行的,举个反例:n=3, v=1...
  • qq_33279781
  • qq_33279781
  • 2016-07-30 16:41:00
  • 1126

HDU-2639-Bone Collector II

这个题是HDU-2602-Bone Collector升级版,改为求第k大的值 思路: 将背包的维数增加一维,存的时候注意去重~ 代码: #include #include #include ...
  • z309241990
  • z309241990
  • 2013-07-06 23:05:20
  • 993

HDU2602 01背包入门 Bone Collector【01背包模板题】

Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Colle...
  • hello_sheep
  • hello_sheep
  • 2017-05-05 16:32:39
  • 254

Bone Collector+hdu+一道01背包的最基本模板

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...
  • u012870383
  • u012870383
  • 2014-08-16 15:55:41
  • 569

ACM刷题之HDU————Bone Collector

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T...
  • xiaofeng187
  • xiaofeng187
  • 2017-02-22 19:44:10
  • 423
收藏助手
不良信息举报
您举报文章:Bone Collector HDU 2602 DP 01 背包
举报原因:
原因补充:

(最多只允许输入30个字)