-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBOJ2156.java
More file actions
47 lines (36 loc) · 1.21 KB
/
BOJ2156.java
File metadata and controls
47 lines (36 loc) · 1.21 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ2156 {
static int n;
static int[] array, dp;
private static void input() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
array = new int[10001];
dp = new int[10001];
for (int i = 1; i <= n; i++) {
array[i] = Integer.parseInt(br.readLine());
}
}
public static void main(String[] args) throws IOException {
input();
process();
}
private static void process() {
setDp();
System.out.println(dp[n]);
}
private static void setDp() {
// set init
dp[1] = array[1];
dp[2] = array[1] + array[2];
for (int i = 3; i <= n; i++) {
int case1 = dp[i-1]; // 현재 포도잔 안마심
int case2 = dp[i-2] + 0 + array[i];// 현재 포도잔 마심1
int case3 = dp[i-3] + 0 + array[i-1] + array[i];// 현재 포도잔 마심2
dp[i] = Math.max(case1, Math.max(case2, case3));
}
}
}