전깃줄(2565)
LIS(Longest Increasing Subsequence)를 구하는 문제
Last updated
LIS(Longest Increasing Subsequence)를 구하는 문제
Last updated
8
1 8
3 9
2 2
4 1
6 4
10 10
9 7
7 63import java.io.*;
import java.util.*;
public class Main{
static int N;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
N = Integer.parseInt(br.readLine());
int dp[] = new int[N+1];
int line[][] = new int[N+1][2];
for(int i=1; i<=N; i++){
st = new StringTokenizer(br.readLine(), " ");
line[i][0] = Integer.parseInt(st.nextToken());
line[i][1] = Integer.parseInt(st.nextToken());
}
//line n번째 - 1 번호 부터 n번째 -2 번호까지
Arrays.sort(line, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
return o1[0] - o2[0];
}
});
int max = 1;
for(int i=1; i<=N; i++){
dp[i] = 1;
for(int j=1; j<i; j++){
if(line[i][1] > line[j][1]){
dp[i] = Math.max(dp[i], dp[j]+1);
}
}
max = Math.max(dp[i], max);
}
System.out.println(N-max);
}
}