标签:
最大子矩阵...悬线法..时间复杂度O(nm) http://blog.csdn.net/wzq_qwq/article/details/47167707
悬线法就是记录一个H向上延伸的最大长度(悬线), L, R向左向右延伸的最大长度, 然后通过递推来得到.
------------------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
#define ok(c) ((c) == ‘F‘ || (c) == ‘R‘)
const int maxn = 1009;
int H[maxn][maxn], L[maxn][maxn], R[maxn][maxn], N, M;
bool F[maxn][maxn];
void Read() {
cin >> N >> M;
for(int i = 0; i < N; i++)
for(int j = 0; j < M; j++) {
char c = getchar();
for(; !ok(c); c = getchar());
F[i][j] = c == ‘F‘;
}
}
int main() {
Read();
for(int i = 0; i < N; i++) {
L[i][0] = F[i][0];
for(int j = 1; j < M; j++)
L[i][j] = F[i][j] ? L[i][j - 1] + 1 : 0;
R[i][M - 1] = F[i][M - 1];
for(int j = M - 2; ~j; j--)
R[i][j] = F[i][j] ? R[i][j + 1] + 1 : 0;
}
memset(H, 0, sizeof H);
for(int i = 1; i < N; i++)
for(int j = 0; j < M; j++) if(F[i][j] && F[i - 1][j]) {
H[i][j] = H[i - 1][j] + 1;
L[i][j] = min(L[i][j], L[i - 1][j]);
R[i][j] = min(R[i][j], R[i - 1][j]);
}
int ans = 0;
for(int i = 0; i < N; i++)
for(int j = 0; j < M; j++) if(F[i][j])
ans = max(ans, (H[i][j] + 1) * (L[i][j] + R[i][j] - 1));
cout << 3 * ans << "\n";
return 0;
}
------------------------------------------------------------------
BZOJ 3039: 玉蟾宫( 悬线法 )
标签:
原文地址:http://www.cnblogs.com/JSZX11556/p/4715241.html