Bone Collector /*一维坐标*/ #include<bits/stdc++.h> using namespace std; #define MAX 1001 int main() { int s[MAX]; int a[MAX],v[MAX]; int T,n,V; cin>>T; while(T--){ cin>>n>>V; for(int i=0; i<n; i++){ cin>>a[i]; } for(int i=0; i<n; i++){ cin>>v[i]; } memset(s,0,sizeof(s)); for(int i=0; i<n; i++){ for(int j=V; j>=v[i]; j--){ s[j] = max(s[j], s[j-v[i]] + a[i]); } } cout<<s[V]<<endl; } return 0; } /*二维坐标*/ #include<bits/stdc++.h> using namespace std; #define MAX 1001 int w[MAX],v[MAX]; int dp[MAX][MAX]; int main() { int n,V; int T; cin>>T; while(T--){ cin>>n>>V; for(int i=1; i<=n; i++){ cin>>v[i]; } for(int i =1 ;i<=n; i++){ cin>>w[i]; } memset(dp,0,sizeof(dp)); for(int i=0;i<=V;i++) dp[0][i]=0; for(int i=1;i<=n;i++){ for(int j=0;j<=V;j++){ if(j>=w[i]){ dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]); }else{ dp[i][j]=dp[i-1][j]; } } } cout<<dp[n][V]<<endl; } return 0; }