Skip to content

Commit ba094eb

Browse files
authored
Create 4.py
1 parent fe8da4e commit ba094eb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

16/4.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
n = int(input())
2+
data = list(map(int, input().split()))
3+
# 순서를 바꾸어 '최장 증가 부분 수열' 문제로 변환
4+
data.reverse()
5+
6+
# LCS 알고리즘 수행
7+
dp = [1] * n
8+
for i in range(1, n):
9+
for j in range(0, i):
10+
if data[j] < data[i]:
11+
dp[i] = max(dp[i], dp[j] + 1)
12+
13+
# 열외해야 하는 병사의 최소 수를 출력
14+
print(n - max(dp))

0 commit comments

Comments
 (0)