https://www.acmicpc.net/problem/2579
[JAVA]
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main{
static int N;
static int[] step;
static int[] dp;
public static void main(String[] args) throws Exception{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
N=Integer.parseInt(br.readLine());
step=new int[301];
dp=new int[301];
for(int i=1; i<=N; i++) {
step[i]=Integer.parseInt(br.readLine());
}
dp[1]=step[1];
dp[2]=step[1]+step[2];
dp[3]=Math.max(step[1]+step[3], step[2]+step[3]);
for(int i=4; i<=N; i++) {
dp[i]=Math.max(dp[i-2]+step[i], dp[i-3]+ step[i - 1]+step[i]);
}
System.out.println(dp[N]);
}
}
'알고리즘 문제풀이 > 백준' 카테고리의 다른 글
[백준 16988] Baaaaaaaaaduk2(Easy) (JAVA) (0) | 2020.04.27 |
---|---|
[백준 16973] 직사각형 탈출(JAVA) (1) | 2020.04.18 |
[백준 1753] 최단경로(JAVA/C++) (0) | 2020.04.10 |
[백준 2225] 합분해(JAVA) (0) | 2020.04.07 |
[백준 17404] RGB거리2(JAVA) (0) | 2020.04.04 |
댓글