HDU 2602 Bone Collector
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define max 1010
struct bone
{
int ve , value ;
}num[max] ;
int T , N , V , Mv[max] ;
int cmp ( int a , int b )
{
return a > b ? a : b ;
}
int main ()
{
scanf ( "%d" , &T ) ;
while ( T -- ) {
scanf ( "%d%d" , &N , &V ) ;
for ( int i = 1 ; i <= N ; i ++ )
scanf ( "%d" , &num[i].value ) ;
for ( int i = 1 ; i <= N ; i ++ )
scanf ( "%d" , &num[i].ve ) ;
for ( int i = 0 ; i <= V ; i ++ )
Mv[i] = 0 ;
for ( int i = 1 ; i <= N ; i ++ )
for ( int j = V ; j >= num[i].ve ; j -- )
Mv[j] = cmp ( Mv[j] , Mv[j - num[i].ve] + num[i].value ) ;
printf ( "%d\n" , Mv[V] ) ;
}
return 0 ;
}
#include<string.h>
#include<stdlib.h>
#define max 1010
struct bone
{
int ve , value ;
}num[max] ;
int T , N , V , Mv[max] ;
int cmp ( int a , int b )
{
return a > b ? a : b ;
}
int main ()
{
scanf ( "%d" , &T ) ;
while ( T -- ) {
scanf ( "%d%d" , &N , &V ) ;
for ( int i = 1 ; i <= N ; i ++ )
scanf ( "%d" , &num[i].value ) ;
for ( int i = 1 ; i <= N ; i ++ )
scanf ( "%d" , &num[i].ve ) ;
for ( int i = 0 ; i <= V ; i ++ )
Mv[i] = 0 ;
for ( int i = 1 ; i <= N ; i ++ )
for ( int j = V ; j >= num[i].ve ; j -- )
Mv[j] = cmp ( Mv[j] , Mv[j - num[i].ve] + num[i].value ) ;
printf ( "%d\n" , Mv[V] ) ;
}
return 0 ;
}