http://acm.hdu.edu.cn/showproblem.php?pid=1505 1506的进一步运用 #include<iostream> using namespace std; #define N 1001 int r[N],l[N]; bool map[N][N]; int h[2][N]; int n,m; void init() { for(int i=1;i<=m;i++) l[i]=r[i]=i; } int main(void) { int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); char ch[2]; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { scanf("%s",ch); if(ch[0]=='F') map[i][j]=1; else map[i][j]=0; } memset(h,0,sizeof(h)); for(int j=1;j<=m;j++) if(map[1][j]) h[1][j]=1; int ans=0; for(int i=1;i<=n;i++) { int k=i%2; init(); if(i!=1) { for(int j=1;j<=m;j++) { if(map[i][j]) h[k][j]=h[1-k][j]+1; else h[k][j]=0; } } for(int j=1;j<=m;j++) while(l[j]>1&&h[k][l[j]-1]>=h[k][j]) l[j]=l[l[j]-1]; for(int j=m;j>=1;j--) while(r[j]<m&&h[k][r[j]+1]>=h[k][j]) r[j]=r[r[j]+1]; for(int j=1;j<=m;j++) { int temp=(r[j]-l[j]+1)*h[k][j]; if(ans<temp) ans=temp; } } printf("%d/n",ans*3); } } 一行行处理就好