[알고리즘/백준] 2579번 : 계단 오르기(python)

유현민·2022년 3월 22일
0

알고리즘

목록 보기
70/253


처음에는 앞으로 가는 경우만 생각했는데 이미 올라온 경우를 생각해야 하는 문제였다..

N = int(input())
a = [0]
for _ in range(N):
    a.append(int(input()))
dp = [0] * (N+1)

if N == 1:
    print(a[1])
else:
    dp[1] = a[1]
    dp[2] = a[1] + a[2]

    for i in range(3, N+1):
        dp[i] = max(dp[i-3] + a[i-1]+a[i], dp[i-2]+a[i])
    print(dp[N])
profile
smilegate megaport infra

0개의 댓글