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.

44 lines
1002 B

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;
typedef pair<int, int> PII;
#define x first
#define y second
const int N = 600;
int ans, f[N];
PII a[N];
int main() {
#ifndef ONLINE_JUDGE
freopen("POJ1548.in", "r", stdin);
#endif
while (true) {
memset(f, 0, sizeof f);
ans = 0;
int al = 0;
while (true) {
int x, y;
scanf("%d %d", &x, &y);
if (x == -1) exit(0);
if (x == 0) break;
a[al++] = make_pair(x, y);
}
sort(a, a + al);
// LIS
for (int i = 0; i < al; i++) f[i] = 1; // DP初始化
for (int i = 0; i < al; i++)
for (int j = 0; j < i; j++)
if (a[j].y > a[i].y) f[i] = max(f[i], f[j] + 1);
// Dilworth
for (int i = 0; i < al; i++) ans = max(ans, f[i]);
printf("%d\n", ans);
}
return 0;
}