728x90
https://www.acmicpc.net/problem/2579
# dp[0] = stair[0]
# dp[1] = stair[0] + stair[1]
# dp[2] = max(stair[0] + stair[2], stair[1] + stair[2])
# dp[3:] = max(dp[i - 3] + stair[i - 1] + s[i], dp[i - 2] + s[i])
import sys
input = sys.stdin.readline
N = int(input())
stair = [0] * (N + 1)
dp = [0] * (N + 1)
for i in range(N):
M = int(input())
stair[i] = M
dp[0] = stair[0]
dp[1] = stair[1] + stair[0]
if N >= 3:
dp[2] = max(stair[0] + stair[2], stair[1] + stair[2])
for i in range(3, N):
dp[i] = max(dp[i - 3] + stair[i - 1] + stair[i], dp[i - 2] + stair[i])
print(dp[N - 1])
728x90
'Study > Coding Test' 카테고리의 다른 글
[백준] 11727 - 2×n 타일링 2 Python (0) | 2023.06.05 |
---|---|
[백준] 11726 - 2×n 타일링 Python (0) | 2023.06.04 |
[백준] 1463 - 1로 만들기 Python (0) | 2023.06.02 |
[백준] 17070 - 파이프 옮기기1 Python (0) | 2023.05.23 |
[백준] 10815 - 숫자 카드 Python (0) | 2023.05.23 |