Skip to content

Commit 56e2f98

Browse files
committed
[BOJ] #11054. 가장 긴 바이토닉 부분 수열 / 골드4 / 60분 / 힌트
1 parent 21eeea0 commit 56e2f98

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
# 1. 입력 처리
5+
n = int(input()) # 수열의 크기
6+
nums = list(map(int, input().split())) # 수열 A
7+
8+
# 2. 증가 부분 수열 계산 (왼쪽 → 오른쪽)
9+
inc = [1] * n
10+
for i in range(n):
11+
for j in range(i):
12+
if nums[i] > nums[j]:
13+
inc[i] = max(inc[i], inc[j] + 1)
14+
15+
# 3. 감소 부분 수열 계산 (오른쪽 → 왼쪽)
16+
dec = [1] * n
17+
for i in range(n - 1, -1, -1):
18+
for j in range(i + 1, n):
19+
if nums[i] > nums[j]:
20+
dec[i] = max(dec[i], dec[j] + 1)
21+
22+
# 4. 가장 긴 바이토닉 수열의 길이 계산
23+
result = 0
24+
for i in range(n):
25+
result = max(result, inc[i] + dec[i] - 1)
26+
27+
# 5. 결과 출력
28+
print(result)

0 commit comments

Comments
 (0)