Skip to content

Commit 2242a59

Browse files
authored
[BOJ] 2565 전깃줄 (G5)
1 parent ab84a07 commit 2242a59

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

김지호/4주차/260124.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# https://www.acmicpc.net/problem/2565
2+
3+
from collections import defaultdict
4+
import sys
5+
from collections import deque
6+
7+
sys.stdin = open("./input.txt",'r')
8+
9+
N = int(input())
10+
11+
wires = []
12+
for _ in range(N):
13+
wires.append(list(map(int,input().split(" "))))
14+
15+
wires.sort(key=lambda x:(x[0],x[1]))
16+
b_positions = [w[1] for w in wires]
17+
# b를 기준으로 가장 증가하는 부분 수열 구하기 (LTS)
18+
dp = [1] * N
19+
20+
for i in range(N):
21+
for j in range(i):
22+
if(b_positions[j] < b_positions[i]):
23+
dp[i] = max(dp[i],1 + dp[j])
24+
# print(wires)
25+
# print(dp)
26+
# 정답 : 최대 부분수열 길이 > 전체 길이 - 최대
27+
print(N - max(dp))

0 commit comments

Comments
 (0)