๐ฆ ๊ฐ์ฅ ๊ธด ๋ฐ์ดํ ๋ ๋ถ๋ถ ์์ด
1. ๋ฌธ์ ๋งํฌ
11054๋ฒ: ๊ฐ์ฅ ๊ธด ๋ฐ์ดํ ๋ ๋ถ๋ถ ์์ด
2. ์ฝ๋
Python3
31120KB
284ms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
N = int(input())
A = list(map(int, input().split()))
dp_up = [1] * N
dp_down = [1] * N
# ์ค๋ฆ์ฐจ์ DP
for i in range(N):
for j in range(i):
if A[j] < A[i]:
dp_up[i] = max(dp_up[j] + 1, dp_up[i])
# ๋ด๋ฆผ์ฐจ์ DP
for i in range(N - 1, -1, -1):
for j in range(N - 1, i, -1):
if A[j] < A[i]:
dp_down[i] = max(dp_down[j] + 1, dp_down[i])
result = 0
for i in range(N):
result = max(dp_up[i] + dp_down[i] - 1, result);
print(result)
3. ํด์ค
์์๋ถํฐ, ๋ง์ง๋ง๋ถํฐ ์์ํ๋ ์ค๋ฆ์ฐจ์ DP๋ฅผ ๋๊ฐ ๋ง๋ฌ
๋ DP์ MAX ๊ฐ์ด ์ฆ๊ฐํ๋ค๊ฐ ๊ฐ์ํ๋ ๋ถ๋ถ ์์ด์ด ๋๋ค
This post is licensed under CC BY 4.0 by the author.