LA 3029
To find the maximum sub-matrix problem, mainly consider the enumeration method, the direct enumeration is definitely not possible, because the number of sub-matrices of a large matrix is a number of points, so you should consider before the enumeration of the scanning work.
Use the Left,right,up array to record the maximum distance from the i,j position to the left, right, and above, then end with just enumerating each block (Right-left) *up
#include <iostream>#include<cstdio>#include<cstring>#defineM (a) memset (A,0,sizeof (a))Const intmaxn=1e3+Ten;CharA[MAXN][MAXN];intUP[MAXN][MAXN],RIGHT[MAXN][MAXN],LEFT[MAXN][MAXN];intM,n;intMaxintX1,intx2) { returnX1>x2?x1:x2;}intMinintX1,intx2) { returnX1>x2?x2:x1;}voidInit () {scanf ("%d%d",&m,&N); for(intI=1; i<=m; i++) for(intj=1; j<=n; J + +) std::cin>>A[i][j]; M (UP); M (right); M (left); for(intI=1; i<=m; i++) { intlo=0; for(intj=1; j<=n; J + +) { if(a[i][j]=='R') {Up[i][j]=0; LEFT[I][J]=0; Lo=J; } Else { if(i==1) {Up[i][j]=1; LEFT[I][J]=lo+1; } Else{Up[i][j]=up[i-1][j]+1; LEFT[I][J]=max (lo+1, left[i-1][j]); } } } intro=n+1; for(intJ=n; j>=1; j--) { if(a[i][j]=='R') {Right[i][j]=n+1; Ro=J; } Else { if(i==1) {Right[i][j]=ro-1; } Else{Right[i][j]=min (ro-1, right[i-1][j]); } } } }}voidWork () {intans=-1e9; for(intI=1; i<=m; i++) for(intj=1; j<=n; J + +) {ans=max (ans, (right[i][j]-left[i][j]+1)*Up[i][j]); } printf ("%d\n",3*ans);}intMain () {intT; scanf ("%d",&T); while(t--) {Init (); Work (); } return 0;}
View Code
F-city Game