HDU 1505

来源:互联网 发布:禁止吸烟网络图片大全 编辑:程序博客网 时间:2024/06/05 16:04

HDU 1506 加强版

http://blog.csdn.net/a634771197/article/details/26506999

先求出每个点往下能达到的最大高度,然后往两边推,求最大宽度,再求最大面积,注意输入


#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#define N 1005using namespace std;int  map[N][N],h[N][N],dpl[N],dpr[N];char tmp[3];int main(){    int ans,k,i,j,n,m,temp,t;    scanf("%d",&k);    while(k--){        memset(map,0,sizeof(map));        scanf("%d%d",&n,&m);        for(i=1;i<=n;i++){            for(j=1;j<=m;j++){                scanf("%s",tmp);                if(tmp[0]=='F')                map[i][j]=1;            }        }        memset(h,0,sizeof(h));        for(i=n;i>=1;i--){            for(j=1;j<=m;j++){                if(map[i][j])                h[i][j]=h[i+1][j]+1;                else                h[i][j]=0;            }        }        ans=0;        for(i=1;i<=n;i++){            dpl[1]=1;            dpr[m]=m;            for(j=2;j<=m;j++){                t=j;                while(h[i][t-1]>=h[i][j]&&t>1)                t=dpl[t-1];                dpl[j]=t;            }            for(j=m-1;j>=1;j--){                t=j;                while(h[i][t+1]>=h[i][j]&&t<m)                t=dpr[t+1];                dpr[j]=t;            }            for(j=1;j<=m;j++){                temp=(dpr[j]-dpl[j]+1)*h[i][j];                if(temp>ans)                ans=temp;            }        }        printf("%d\n",ans*3);    }    return 0;}


0 0
原创粉丝点击