728x90
๋ฌธ์
ํ์ด
๊ฐ์ฅ ๊ธด ์ฆ๊ฐํ๋ ๋ถ๋ถ ์์ด๊ณผ ๊ฐ์ฅ ๊ธด ๊ฐ์ํ๋ ๋ถ๋ถ ์์ด์ ๊ตฌํ๋ฉด ๋๋ค.
(๋ถ๋ถ ์์ด ์๋ฆฌ์ฆ๋ฅผ ํ์๋ค๋ฉด ์ฝ๊ฒ ํ ์ ์๋ค.)
์ฝ๋
import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
dpMax = [1] * n
dpMin = [1] * n
for i in range(1, n):
for j in range(i):
if arr[i] > arr[j]:
dpMax[i] = max(dpMax[i], dpMax[j] + 1)
for i in range(n - 1, -1, -1):
for j in range(i, n):
if arr[i] > arr[j]:
dpMin[i] = max(dpMin[i], dpMin[j] + 1)
print(max([a + b for a, b in zip(dpMax, dpMin)]) - 1)
๋ง๋ฌด๋ฆฌ
๋ถ๋ถ ์์ด ๋ฌธ์ ๋ ์ด์ ์ด๋ ์ ๋(?) ๋ง์คํฐํ ๊ฑฐ ๊ฐ๋ค.
728x90