思路:HDU1506,1505的加强版,枚举几种情况然后像1506,1505那样DP即可
#include<bits\stdc++.h> using namespace std; const int maxn = 1005; int h[maxn][maxn]; int l[maxn],r[maxn]; char s[maxn][maxn]; int n,m,ans=0; void gan() { for(int i = 1;i<=n;i++) { for(int j = 1;j<=m;j++) l[j]=r[j]=j; h[i][0]=h[i][m+1]=-1; for(int j = 1;j<=m;j++) while(h[i][j]<=h[i][l[j]-1]) l[j]=l[l[j]-1]; for(int j = m;j>=1;j--) while(h[i][j]<=h[i][r[j]+1]) r[j]=r[r[j]+1]; for(int j = 1;j<=m;j++) ans = max(ans,h[i][j]*(r[j]-l[j]+1)); } } int main() { while(scanf("%d%d",&n,&m)!=EOF) { ans=0; for(int i = 1;i<=n;i++) scanf("%s",s[i]+1); for(int i = 1;i<=n;i++) for(int j =1;j<=m;j++) if(s[i][j]=='a'||s[i][j]=='w'||s[i][j]=='y'||s[i][j]=='z') h[i][j]=h[i-1][j]+1; else h[i][j]=0; gan(); for(int i = 1;i<=n;i++) for(int j = 1;j<=m;j++) if(s[i][j]=='b'||s[i][j]=='w'||s[i][j]=='x'||s[i][j]=='z') h[i][j]=h[i-1][j]+1; else h[i][j]=0; gan(); for(int i = 1;i<=n;i++) for(int j = 1;j<=m;j++) if(s[i][j]=='c'||s[i][j]=='x'||s[i][j]=='y'||s[i][j]=='z') h[i][j]=h[i-1][j]+1; else h[i][j]=0; gan(); printf("%d\n",ans); } }
Description
Input
Output
Sample Input
2 4 abcw wxyz
Sample Output
3