//01背包优化: #include <iostream> #include<memory.h> #include<cstdio> using namespace std; struct per { int money,exp; }p[1001]; int dp[1000001]; int main() { int N,T,M,i,j,sum; scanf("%d",&T); while(T--) { memset(dp,0,sizeof(dp)); scanf("%d%d",&N,&M); sum = 0; for(i=0; i<N; ++i) { scanf("%d%d",&p[i].money,&p[i].exp); sum += p[i].money; } for(i=0; i<N; ++i) { sum -= p[i].money; int cm = M - sum > p[i].money ? M - sum : p[i].money; for(j=M; j>=cm; --j) if(dp[j] < dp[j-p[i].money] + p[i].exp) dp[j] = dp[j-p[i].money] + p[i].exp; } printf("Max experience: %d\n",dp[M]); } return 0; }