BOJ - 2579 - 계단 오르기
Updated:
def solution():
N = int(input())
stair = []
for i in range(N):
stair.append(int(input()))
if len(stair) == 1:
print(stair[0])
return
elif len(stair) == 2:
print(stair[0] + stair[1])
return
dp = []
dp.append(stair[0])
dp.append(stair[1] + stair[0])
dp.append(max(stair[2] + stair[0], stair[2] + stair[1]))
for i in range(3, N):
dp.append(max(stair[i] + dp[i - 2], stair[i] + stair[i - 1] + dp[i - 3]))
print(dp[N - 1])
solution()
https://www.acmicpc.net/problem/2579
Leave a comment