11055-s2 성공

This commit is contained in:
sm4640
2026-03-27 17:00:42 +09:00
parent 3a802d35c3
commit 5d7eebc8f1

View File

@@ -0,0 +1,29 @@
# 가장 큰 증가하는 부분 수열
import sys
input = sys.stdin.readline
def solution():
n = int(input().rstrip())
lst = list(map(int, input().rstrip().split()))
dp = lst[:]
for i in range(1, n):
dp[i] = max([dp[j]+lst[i] for j in range(i-1, -1, -1) if lst[j] < lst[i]] + [lst[i]])
print(max(dp))
return
solution()
"""
걸린 시간: 25분
시간 복잡도: 하나의 값을 볼때 내 앞에 있는 값들을 다 확인해봐야하기 때문에 O(n^2)이다.
해설: 현재 보는 값보다 앞에 나온 작은 놈들의 dp 값에 나를 더하면, 이는 앞에 나온 수열 중 내가 붙을 수 있는 것들 중에 값이 최대인 것에 붙겠다라는 뜻이다.
"""