2602 Bone Collector dp-3

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

不知道为什么老是WA,以后再来研究吧

 1 #include <iostream>
 2 #include <cstring>
 3 #include <algorithm>
 4 #include <cmath>
 5 using namespace std;
 6
 7 int main()
 8 {
 9     int n,t,V,v[1005],w[1005],ans[1005];
10     cin>>t;
11     while(t--)
12     {
13         cin>>n>>V;
14         for(int i=0;i<n;i++)
15         cin>>v[i];
16         for(int i=0;i<n;i++)
17         cin>>w[i];
18         memset(ans,0,sizeof(ans));
19         for(int i=0;i<n;i++)
20         {
21             for(int j=V;j>=v[i];j--)
22             if(ans[j]<ans[j-v[i]]+w[i])
23             ans[j]=ans[j-v[i]]+w[i];
24         }
25         cout<<ans[V]<<endl;
26     }
27     return 0;
28 }

参考

http://www.cnblogs.com/yangcl/archive/2011/11/07/2240377.html

时间: 2024-08-02 06:58:46

2602 Bone Collector dp-3的相关文章

HDU 2602 Bone Collector DP(01背包)

Bone Collector Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u 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 , c

杭电 2602 Bone Collector

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 27413    Accepted Submission(s): 11154 Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bo

HDU 2602 Bone Collector 0/1背包

题目链接:pid=2602">HDU 2602 Bone Collector Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 28903    Accepted Submission(s): 11789 Problem Description Many years ago , in Teddy's h

hdu 2602 Bone Collector(01背包)模板

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 54132    Accepted Submission(s): 22670 Problem Description Many years ago , in

hdu 2602 Bone Collector (简单01背包)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 30486    Accepted Submission(s): 12550 Problem Description Many years ago , in

HDOJ 2602 Bone Collector【01背包】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 34251    Accepted Submission(s): 14101 Problem Description Many years ago , in

hdu 2602 Bone Collector 【01背包模板】

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 40404    Accepted Submission(s): 16786 Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bo

hdoj 2602 Bone Collector【0-1背包】【dp思想】

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 40247    Accepted Submission(s): 16722 Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bo

HDU 2602 Bone Collector(01背包裸题)

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 60469    Accepted Submission(s): 25209 Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bo

HDU 2602 Bone Collector (01背包问题)

原题代号:HDU 2602 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 原题描述: 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 ,