You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.4 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
pair<int, int> x[N]; //数据一对一对读入用pair或者创建一个struct
int f[N];
/*
LIS线
线LIS
*/
int main() {
//输入+输出重定向
freopen("../1280.txt", "r", stdin);
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> x[i].first >> x[i].second;
//按pair的first进行排序那么second自动配合上
sort(x + 1, x + 1 + n);
//输出看一下
for (int i = 1; i <= n; ++i) {
cout << x[i].first << "," << x[i].second << " ";
}
cout << endl;
//转化为最长上升子序列问题
for (int i = 1; i <= n; i++) {
f[i] = 1;
for (int j = 1; j < i; j++) {
if (x[i].second > x[j].second) f[i] = max(f[i], f[j] + 1);
}
}
int res = 0;
//找出最大值
for (int i = 1; i <= n; i++) res = max(res, f[i]);
cout << res << endl;
//关闭文件
fclose(stdin);
return 0;
}