HDU 2602 Bone Collector

Bone Collector

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


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
 1 #include<stdio.h>
2 #include<string.h>
3 #include<stdlib.h>
4 #define max 1010
5 struct bone
6 {
7 int ve , value ;
8 }num[max] ;
9 int T , N , V , Mv[max] ;
10 int MAX ( int a , int b )
11 {
12 return a > b ? a : b ;
13 }
14
15 int main ()
16 {
17 scanf ( "%d" , &T ) ;
18 while ( T -- ) {
19 scanf ( "%d%d" , &N , &V ) ;
20 for ( int i = 1 ; i <= N ; i ++ )
21 scanf ( "%d" , &num[i].value ) ;
22 for ( int i = 1 ; i <= N ; i ++ )
23 scanf ( "%d" , &num[i].ve ) ;
24 for ( int i = 0 ; i <= V ; i ++ )
25 Mv[i] = 0 ;
26 for ( int i = 1 ; i <= N ; i ++ )
27 for ( int j = V ; j >= num[i].ve ; j -- )
28 Mv[j] = MAX ( Mv[j] , Mv[j - num[i].ve] + num[i].value ) ; // 状态方程
29 printf ( "%d\n" , Mv[V] ) ;
30 }
31 return 0 ;
32 }

  

posted @ 2011-08-08 15:54  贺佐安  阅读(603)  评论(0编辑  收藏  举报