bzoj 3039 悬线法 最大子矩阵问题

61 篇文章 0 订阅
3 篇文章 0 订阅

题意:给出一个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


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值