朴素版本01背包
import java.util.*;
public class Main {
static final int N = 1010;
static int[][] f = new int[N][N];
static int[] v = new int[N], w = new int[N];
static int n, m;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
m = sc.nextInt();
for (int i = 1; i <= n; i++) {
v[i] = sc.nextInt();
w[i] = sc.nextInt();
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
f[i][j] = f[i - 1][j];//不选第i件物品
if (j >= v[i]) f[i][j] = Math.max(f[i][j], f[i - 1][j - v[i]] + w[i]);
//选择第i件物品
}
System.out.println(f[n][m]);
}
}