杭电2602
1 //01背包,详见背包九讲 2 #include<stdio.h> 3 #include<string.h> 4 typedef struct 5 { 6 int val,room; 7 } cus; 8 int an[1005]; 9 cus inf[1005]; 10 int main() 11 { 12 int n; 13 scanf("%d",&n); 14 while(n--) 15 { 16 memset(an,0,sizeof an); 17 memset(inf,0,sizeof inf); 18 int num,Room,ans=0; 19 scanf("%d%d",&num,&Room); 20 for(int i=0; i<num; ++i) 21 scanf("%d",&inf[i].val); 22 for(int i=0; i<num; ++i) 23 scanf("%d",&inf[i].room); 24 for(int i=0; i<num; ++i) 25 { 26 for(int j=inf[i].room; j<=Room; ++j) 27 { 28 int seet=j-inf[i].room; 29 int temp=an[j]+inf[i].val; 30 if(an[seet] < temp) 31 an[seet]=temp; 32 if(temp > ans) 33 ans=temp; 34 } 35 } 36 printf("%d\n",ans); 37 } 38 return 0; 39 }