AcWing 1012. 友好城市
原题链接
简单
作者:
不知名的fE
,
2024-11-18 13:16:08
,
所有人可见
,
阅读 1
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static final int N = 5010;
static int[][] a = new int[N][2];
static int[] f = new int[N];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
for (int i = 1; i <= n; i++) {
String[] s = sc.nextLine().split(" ");
a[i] = new int[]{Integer.parseInt(s[0]), Integer.parseInt(s[1])};
}
Arrays.sort(a, 1, n + 1, (o1, o2) -> o1[1] - o2[1]);//随便按照一端排序另一端求上升子序列即可
int res = 0;
for (int i = 1; i <= n; i++) {
f[i] = 1;
for (int j = 1; j < i; j++) {
if (a[i][0] > a[j][0]) f[i] = Math.max(f[i], f[j] + 1);
}
res = Math.max(res, f[i]);
}
System.out.println(res);
}
}