백준2579 2xn 계단 오르기(파이썬)


백준1463 1로 만들기(파이썬)

https://www.acmicpc.net/problem/2579 baek2579-1.jpg
baek2579-2.jpg

코드

n = int(input())
s = [0 for i in range(301)]
dp = [0 for i in range(301)]
for i in range(n):
    s[i] = int(input())
dp[0] = s[0]
dp[1] = s[0] + s[1]
dp[2] = max(s[1] + s[2], s[0] + s[2])
for i in range(3, n):
    dp[i] = max(dp[i - 3] + s[i - 1] + s[i], dp[i - 2] + s[i])
print(dp[n - 1])





© 2021.07. by 전은성

Powered by 전은성