题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2870
分析:[HDU 1505的加深版] 因为a,b,c三种不同字母(w,x,y,z可以不考虑,因为它们都要以变为a,b,c),相比于1505题,只要再加一维将a,b,c区别开就行.
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
int L[4][1005],R[4][1005],h[4][1005];
int main(){
int n,m;
while(cin>>n>>m){
memset(h,0,sizeof(h));
int maxs=0;
for(int i=0;i<n;++i){
string s; cin>>s;
for(int j=0;j<m;++j){
if(s[j]=='z') ++h[1][j],++h[2][j],++h[3][j];
else if(s[j]=='w') ++h[1][j],++h[2][j],h[3][j]=0;
else if(s[j]=='x') ++h[2][j],++h[3][j],h[1][j]=0;
else if(s[j]=='y') ++h[1][j],++h[3][j],h[2][j]=0;
else {
if(s[j]=='a') ++h[1][j],h[2][j]=h[3][j]=0;
if(s[j]=='b') ++h[2][j],h[1][j]=h[3][j]=0;
if(s[j]=='c') ++h[3][j],h[1][j]=h[2][j]=0;
}
for(int k=1;k<=3;++k)
L[k][j]=R[k][j]=j;
}
for(int t=1;t<=3;++t){
for(int j=0,k=m-1;j<m;++j,--k){
while(L[t][j]&&h[t][L[t][j]-1]>=h[t][j])
L[t][j]=L[t][L[t][j]-1];
while(R[t][k]<m-1&&h[t][R[t][k]+1]>=h[t][k])
R[t][k]=R[t][R[t][k]+1];
}
for(int j=0;j<m;++j){
int s=h[t][j]*(R[t][j]-L[t][j]+1);
maxs=max(maxs,s);
}
}
}
cout<<maxs<<endl;
}
return 0;
}