bzoj3039玉蟾宫

分析:这题一开始以为原题。。51nod有一道求最大子矩阵和的方法,但是n^3,这题虽然要求弱了点,但是时间复杂度要求比较高,所以一开始想法是枚举矩阵的顶,然后二分出向左向右最长扩展距离,然后往下扫,但是这样log^2感觉会超。。后来发现单调栈可以直接做。。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n,m;
const int N=1e3+5;
typedef long long ll;
char s[N];
int a[N][N];
int l[N],r[N],h[N],st[N],top=0,ans;
int main()
{
    scanf("%d%d",&n,&m);
    fo(i,1,n)
    {
        fo(j,1,m)
        {
            char ch;
            ch=getchar();
            while(ch!='F'&&ch!='R')ch=getchar();
            if (ch=='F')a[i][j]=1;
        }
    }
    fo(i,1,n)
    {
        fo(j,1,m)
        if (a[i][j])h[j]++;
        else h[j]=0;
        top=0;
        st[top]=0;
        fo(j,1,m)
        {
            while (h[st[top]]>=h[j]&&top)top--;
            l[j]=st[top]+1;
            st[++top]=j;
        }
        top=0;
        st[top]=m+1;
        fd(j,m,1)
        {
            while (h[st[top]]>=h[j]&&top)top--;
            r[j]=st[top]-1;
            st[++top]=j;
        }
        fo(j,1,m)
        ans=max(ans,h[j]*(r[j]-l[j]+1));
    }
    printf("%d\n",ans*3);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值