We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9882015 commit 6cfa7a0Copy full SHA for 6cfa7a0
YoonYn9915/dp/2025-03-15-[백준]-#2579-계단 오르기.py
@@ -0,0 +1,19 @@
1
+import sys
2
+
3
+input = sys.stdin.readline
4
5
+n = int(input())
6
7
+stairs = [0] * 301
8
+for i in range(1, n + 1):
9
+ stairs[i] = int(input())
10
11
+dp = [0] * 301
12
+dp[1] = stairs[1]
13
+dp[2] = stairs[1] + stairs[2]
14
+dp[3] = max(stairs[1] + stairs[3], stairs[2] + stairs[3])
15
16
+for i in range(4, n + 1):
17
+ dp[i] = max(dp[i - 3] + stairs[i - 1] + stairs[i], dp[i - 2] + stairs[i])
18
19
+print(dp[n])
0 commit comments