Skip to content

Commit 67903d8

Browse files
committed
[BOJ] #2579.계단 오르기 / 실버3 / 60(X)
1 parent 33c07a2 commit 67903d8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
N = int(input())
5+
stair = [int(input()) for _ in range(N)]
6+
7+
# N에 따른 예외 처리
8+
if N == 1:
9+
print(stair[0])
10+
exit()
11+
12+
if N == 2:
13+
print(stair[0] + stair[1])
14+
exit()
15+
16+
dp = [0] * (N+1)
17+
dp[0] = stair[0]
18+
dp[1] = stair[0] + stair[1]
19+
dp[2] = max(stair[0] + stair[2], stair[1] + stair[2])
20+
21+
for i in range(3, N):
22+
dp[i] = max(dp[i-2] + stair[i], dp[i-3] + stair[i-1] + stair[i])
23+
24+
print(dp[N-1])

0 commit comments

Comments
 (0)