Files
python/TangDou/AcWing/ErFenTu/2549_LIS.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

41 lines
948 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
#define x first
#define y second
const int N = 1e6 + 10;
int n, m;
int ans, f[N];
PII a[N];
int al;
// 本代码未AC,8/10通过,原因未知
int main() {
#ifndef ONLINE_JUDGE
freopen("2549.in", "r", stdin);
#endif
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
char x;
cin >> x;
if (x == '1') a[al++] = {i, j};
}
// 似乎不需要进行排序,因为上面就是按顺序输入的节点
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;
}