[cpp] /***************** 2013.2.1 hdu 2602 Achiberx time:46ms mem: 4244k http://acm.hdu.edu.cn/showproblem.php?pid=2602 *****************/ #include <iostream> #include <cstdio> #include <cstring> const int maxn = 1010; using namespace std; int n, v, a[maxn][maxn], weight[maxn], value[maxn]; int work() { int i, j; www.2cto.com for(i = 1; i <= n; i++ ) { for(j = 0; j <= v; j++ ) { if(j >= weight[i]) { a[i][j] = max(a[i-1][j], a[i-1][j-weight[i]] + value[i]); } else { a[i][j] = a[i-1][j]; } } } return a[n][v]; } void init() { memset(weight, 0, sizeof(weight)); memset(value, 0, sizeof(value)); for(int i = 0; i < maxn; i++ ) { for(int j = 0; j < maxn; j++ ) { a[i][j] = 0; } } } int main() { int t; scanf("%d", &t); while(t--) { init(); scanf("%d%d", &n, &v); for(int i = 1; i <= n; i++) { scanf("%d", &value[i]); } for(int i = 1; i <= n; i++) { scanf("%d", &weight[i]); } int res = work(); printf("%d\n", res); } return 0; }