-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12865.java
More file actions
27 lines (26 loc) · 847 Bytes
/
12865.java
File metadata and controls
27 lines (26 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int arr[][] = new int[n+1][2];
for(int i=1; i<=n; i++){
arr[i][0]= sc.nextInt(); // weight
arr[i][1]= sc.nextInt(); // value
}
// Max(dp[j-1][i-w[j]] + dp[j][i], dp[j-1][i])
int dp[][] = new int[n+1][k+1];
for(int i=1; i<=k; i++){
for(int j=1; j<=n; j++){
if(arr[j][0]>i) // 담을 수 없으면
{
dp[j][i]=dp[j-1][i];
}
else
dp[j][i]=Math.max(dp[j-1][i-arr[j][0]] + arr[j][1] , dp[j-1][i]);
}
}
System.out.println(dp[n][k]);
}
}