-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_12865.java
More file actions
38 lines (29 loc) ยท 1.1 KB
/
_12865.java
File metadata and controls
38 lines (29 loc) ยท 1.1 KB
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
28
29
30
31
32
33
34
35
36
37
38
package backjoon;
// https://www.acmicpc.net/problem/12865
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class _12865 {
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[] W = new int[N + 1]; // ๋ฌด๊ฒ
int[] V = new int[N + 1]; // ๊ฐ์น
int[] dp = new int[K + 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++) {
// K๋ถํฐ ๋ด์ ์ ์๋ ๋ฌด๊ฒ ํ๊ณ์น๊ฐ ์ด๊ณผํ์ง์์๋ ๊น์ง ๋ฐ๋ณต
for (int j = K; j - W[i] >= 0; j--) {
dp[j] = Math.max(dp[j], dp[j - W[i]] + V[i]);
}
}
System.out.println(dp[K]);
}
}