1. 程式人生 > >poj1924(單調棧求最大矩陣)

poj1924(單調棧求最大矩陣)

urn can memset using for color 矩陣 ring std

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn=1000+10;

bool tu[maxn][maxn];
int h[maxn][maxn],l[maxn],r[maxn];

int main(){
    int n,k,m;
    char c[10];
    scanf("%d",&k);
    while(k--){
        memset(tu,0,sizeof(tu));
        memset(h,
0,sizeof(h)); memset(l,0,sizeof(l)); memset(r,0,sizeof(r)); scanf("%d%d",&n,&m); for (int i=1;i<=n;i++){ for (int j=1;j<=m;j++){ scanf("%s",c); if(c[0]==F) tu[i][j]=true; } } int ans=0;
for (int i=1;i<=n;i++){ for (int j=1;j<=m;j++){ if(tu[i][j]) h[i][j]=h[i-1][j]+1; else tu[i][j]=1; } r[m]=m; l[1]=1; for (int j=m-1;j>=1;j--){ r[j]=j; if(h[i][j]<=h[i][j+1]) r[j]=r[j+1]; }
for (int j=2;j<=m;j++){ l[j]=j; if(h[i][j]<=h[i][j-1]) l[j]=l[j-1]; } for (int j=1;j<=m;j++){ ans=max(ans,h[i][j]*(r[j]-l[j]+1)); } } printf("%d",ans*3); } return 0; }

poj1924(單調棧求最大矩陣)