Skip to content

Commit cdfac9b

Browse files
committed
BOJ_1535 : 안녕
1 parent 67e378c commit cdfac9b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

week6/BOJ_1535(안녕).java

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int N = Integer.parseInt(br.readLine());
9+
int[] hp = new int[N + 1];
10+
int[] happy = new int[N + 1];
11+
int[][] d = new int[N + 1][101];
12+
StringTokenizer st1 = new StringTokenizer(br.readLine());
13+
StringTokenizer st2 = new StringTokenizer(br.readLine());
14+
for (int i = 1; i <= N; i++) {
15+
hp[i] = Integer.parseInt(st1.nextToken());
16+
happy[i] = Integer.parseInt(st2.nextToken());
17+
}
18+
for (int i = 1; i <= N; i++) {
19+
for (int j = 1; j <= 100; j++) {
20+
if (j - hp[i] > 0) {
21+
d[i][j] = Math.max(d[i - 1][j], d[i - 1][j - hp[i]] + happy[i]);
22+
} else {
23+
d[i][j] = d[i - 1][j];
24+
}
25+
}
26+
}
27+
System.out.println(d[N][100]);
28+
}
29+
}

0 commit comments

Comments
 (0)