Skip to content

Commit 21eeea0

Browse files
committed
[BOJ] #2631. 줄세우기 / 골드4 / 50분 / 힌트,성공
1 parent d13f855 commit 21eeea0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
# 1. 입력받기
5+
n = int(input()) # 아이들의 수 N 입력
6+
lines = [int(input()) for _ in range(n)] # 현재 줄 서 있는 상태 입력
7+
8+
# 2. DP 초기화
9+
dp = [1] * n # LIS를 계산하기 위한 초기화 (모든 값 1로 시작)
10+
11+
# 3. LIS 계산
12+
for i in range(1, n): # 현재 위치 i를 기준으로
13+
for j in range(i): # i보다 앞에 있는 모든 j를 탐색
14+
if lines[i] > lines[j]: # 앞 번호가 현재 번호보다 작을 때
15+
dp[i] = max(dp[i], dp[j] + 1) # LIS 길이를 갱신
16+
17+
# 4. 가장 긴 증가하는 부분 수열의 길이 찾기
18+
lis_length = max(dp)
19+
20+
# 5. 최소로 옮겨야 하는 아이들의 수 출력
21+
print(n - lis_length)

0 commit comments

Comments
 (0)