题意:给出一个n*m的矩阵,找出不含'R'的最大子矩阵的面积并乘3
悬线法经典题
这里选择O(nm)的算法
var
n,m,ans,ll,tt :longint;
i,j :longint;
s :ansistring;
h,l,r :array[0..1010,0..1010] of longint;
map :array[0..1010,0..1010] of boolean;
function min(a,b:longint):longint;
begin
if a<b then exit(a) else exit(b);
end;
begin
readln(n,m); ans:=0;
for i:=1 to n do
begin
readln(s);
ll:=length(s); tt:=0;
for j:=1 to ll do
if (s[j]='F') or (s[j]='R') then
begin
inc(tt);
if s[j]='F' then map[i,tt]:=true else map[i,tt]:=false;
end;
end;
//
for i:=1 to n do
begin
for j:=1 to m do
if not map[i,j] then l[i,j]:=0 else l[i,j]:=l[i,j-1]+1;
for j:=m downto 1 do
if not map[i,j] then r[i,j]:=0 else r[i,j]:=r[i,j+1]+1;
end;
//
for i:=1 to n do
for j:=1 to m do
if map[i,j] and map[i-1,j] then
begin
h[i,j]:=h[i-1,j]+1;
l[i,j]:=min(l[i-1,j],l[i,j]);
r[i,j]:=min(r[i-1,j],r[i,j]);
end;
//
for i:=1 to n do
for j:=1 to m do
if (ans<(h[i,j]+1)*(r[i,j]+l[i,j]-1)) then
ans:=(h[i,j]+1)*(l[i,j]+r[i,j]-1);
writeln(3*ans);
end.
——by Eirlys