'commit'
This commit is contained in:
44
TangDou/AcWing/ErFenTu/POJ1548_LIS.cpp
Normal file
44
TangDou/AcWing/ErFenTu/POJ1548_LIS.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user