for (int i = 1; i <= N; i++) {
for (int j = 1; j <= K; j++) {
if (j < W[i]) dp[i][j] = dp[i-1][j];
else dp[i][j] = Math.max(dp[i-1][j], V[i] + dp[i-1][j-W[i]]);
}
}
for (int i = 1; i <= N; i++) {
for (int j = K; j >= W[i]; j--) {
dp[j] = Math.max(dp[j], V[i] + dp[j-W[i]]);
}
}
μΌμ°¨μ λ°°μ΄λ‘ νμ΄νλ, μ΄μ λ¨κ³μ value κ°μ μ¬μ©νκΈ° μν΄μλ λ€μμλΆν° νμνλ©΄ λλ€.