-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ2156.java
More file actions
26 lines (20 loc) · 765 Bytes
/
BOJ2156.java
File metadata and controls
26 lines (20 loc) · 765 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BOJ2156 {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[] dp = new int[N+1];
int[] cost = new int[N+1];
for(int i = 1; i <= N; i++){
cost[i] = Integer.parseInt(br.readLine());
}
dp[1] = cost[1];
dp[2] = cost[1] + cost[2];
for(int i = 3; i <= N; i++){
dp[i] = Math.max(dp[i-1], Math.max(dp[i-2], dp[i-3] + cost[i-1])+cost[i]);
}
System.out.println(dp[N]);
}
}