int[][] combination = new int[N+1][N+1];
combination[1][0] = 1;
combination[1][1] = 1;
// nCk = n-1Ck + n-1Ck-1
for (int i = 2; i < N+1; i++) {
combination[i][0] = 1;
for (int j = 1; j < i+1; j++) {
combination[i][j] = combination[i-1][j] + combination[i - 1][j - 1];
}
}
과정
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());//물건 개수int k = Integer.parseInt(st.nextToken());//최대 무게int[][] dp = new int[n+1][k+1];
int[] w = new int[n+1];//물건의 무게들 int[] v = new int[n+1];//물건의 가치들for (int i = 1; i <= n; i++) {
st = new StringTokenizer(br.readLine());
w[i] = Integer.parseInt(st.nextToken());
v[i] = Integer.parseInt(st.nextToken());
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
if (w[i] <= j) {
dp[i][j] = Math.max(dp[i-1][j-w[i]]+v[i], dp[i-1][j]);
} else {
dp[i][j] = dp[i-1][j];
}
}
}
System.out.print(dp[n][k]);
}
}