반응형
문제 |
소스 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
long[] input = new long[T+1];
for(int i=1; i<=T; i++) {
input[i] = Integer.parseInt(br.readLine());
}
long[] dp = new long[T+1];
dp[1] = input[1];
if(T>1) {
dp[2] = input[1]+input[2];
}
if(T>2) {
for(int i=3; i<=T; i++) {
dp[i] = Math.max(dp[i-3]+input[i-1]+input[i] // OXO
, Math.max(dp[i-2]+input[i] // OOX
, dp[i-1])); // XOO
}
}
System.out.println(dp[T]);
}
}
출처 |
반응형
'알고리즘 > JAVA' 카테고리의 다른 글
[JAVA] 백준 알고리즘 2293 : 동전 1 (DP) (0) | 2019.03.31 |
---|---|
[JAVA] 백준 알고리즘 2839 : 설탕 배달 (0) | 2018.10.11 |
[JAVA] 백준 알고리즘 1912 : 연속합 (DP) (0) | 2018.10.10 |
[JAVA] 백준 알고리즘 1920 : 수 찾기 (0) | 2018.09.20 |
[JAVA] 백준 알고리즘 2869 : 달팽이는 올라가고 싶다 (2) | 2018.09.20 |