-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBOJ11052.java
More file actions
57 lines (45 loc) · 1.34 KB
/
BOJ11052.java
File metadata and controls
57 lines (45 loc) · 1.34 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ11052 {
static int n;
static int[] p;
private static void input() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
// set p array
p = new int[n + 1];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 1; i <= n; i++) {
p[i] = Integer.parseInt(st.nextToken());
}
}
public static void main(String[] args) throws IOException {
input();
process();
}
private static void process() {
for (int i = 2; i <= n; i++) {
dp(i);
}
// print answer
System.out.println(p[n]);
}
private static void dp(int targetIdx) {
int left = 1;
int right = targetIdx - 1;
while(left <= right){
// Exception handling
if(left + right != targetIdx){
System.out.println("logic error");
return;
}
// dp
p[targetIdx] = Math.max(p[targetIdx], p[left] + p[right]);
// move cursor
left++;
right--;
}
}
}