Skip to content

Commit

Permalink
#17 : 2579_계단 오르기
Browse files Browse the repository at this point in the history
  • Loading branch information
ziy00n committed May 10, 2023
1 parent ce06390 commit 772c060
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 이티지윤/2579_계단 오르기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys
input = sys.stdin.readline

n = int(input()) # 계단 개수
s = [int(input()) for _ in range(n)] # 계단 리스트
dp = [0]*(n) # dp 리스트

if len(s)<=2: # 계단 2개 이하
print(sum(s))

else: # 계단이 3개 이상일 때
dp[0] = s[0] # 첫번째 계단
dp[1] = s[0] + s[1] # 두번째 계단

for i in range(2,n): # 세번째 계단부터 dp점화식
dp[i] = max(dp[i-3]+s[i-1]+s[i], dp[i-2]+s[i])

print(dp[-1])

0 comments on commit 772c060

Please sign in to comment.