public static int[][] backpack_solution (int m, int n, int[] W, int[] p) {//c[i][v] means that the first I item fits into a heavy
The maximum value of M's backpack can be obtained int c[][] = new Int[n + 1][m + 1];
for (int i = 0; i < n + 1; i++) c[i][0] = 0;
for (int j = 0; J < m + 1; j +) C[0][j] = 0; for (int i = 1; i < n + 1; i++) {for (int j = 1; j < m + 1; j +) {//when item is the weight of I piece is J, if Part I Weight (w[i-1]) is less than the weight of J, C[i][j] is one of the following two situations://(1) Goods I do not put in the backpack, so c[i][j] for c[i-1][j] Value//(2) items I into the backpack, then the backpack left The remainder weight is j-w[i-1], so the value of c[i][j] is added to the value of the current item I if (w[i-1) <= j) {if (C[i-
1][J] < (C[i-1][j-w[i-1]] + p[i-1])) c[i][j] = c[i-1][j-w[i-1] [+ p[i-1];
else c[i][j] = c[i-1][j];
else c[i][j] = c[i-1][j];
} return C; }