/*
F (i,j) indicates the edge length of the maximum full 0 sub-matrix (I,J) in the lower right corner
If A[i][j]==1,f (i,j) =0
Otherwise: f (i,j) =min{F (i-1,j), F (i,j-1), F (i-1,j-1)}+1
This is the maximum full 0 square sub-matrix
Requires a rectangular matrix, the above ideas do not work
Assume that (I,J) is the largest matrix in the lower right corner =12
It could be 3*4, 4*3, 2*6, 6*2, 1*12, 12*1
According to the above-mentioned idea of state transfer, the scheme to obtain the optimal value is not unique,
All scenarios need to be noted for subsequent state transitions.
In a rectangular full 0 sub-matrix, examine a location (I,J)
In line I, the full 0 interval length containing the (i,j) position >= the width of the rectangle
If line I is the last line of the sub-matrix, the i,j position is upward, and the number of consecutive 0 >= the height of the rectangle
Set [L (I,J). R (I,J)] is a full 0 sub-range containing (I,J) on line I
I1 line to Line I2 and contains (I2,J) the conditions that the sub-matrices should meet:
(I1. I2,J) are high in the 0,i2-i1+1= matrix
(I,J) corresponds to the interval [L (i,j): R (i,j) the width of the]>= matrix
Computes L (i,j), R (I,J) in isolation, and then enumerates i1,i2,j, Time complexity O (n^3)
L (I,J) is related to L (i,j-1), R (I,j) and R (i,j+1);
Define h (I,J) to indicate the number of positions (I,J) up to 0 continuous, H (i,j) and H (I-1,J);
The width of the rectangle depends on [I1. I2] Row in column J [L (I,J): R (I,J)] minimum value
Define L (I,j), R (I,j), respectively, to line I, before the H (i,j) line, all 0 elements of the left and right intervals,
Then the size of the sub-matrix = (R (i,j)-L (i,j) +1) *h (I,J)
The recursive relationship of H (I,J)
if (a[i][j]==0) H (i,j) =h (i,j) +1;
else h (i,j) = 0;
The recursive relationship of L (I,J)
Defines an MX representing the left position before 0 appears, the initial value =1
if (a[i][j]==0) {
L (i,j) =max (L (i-1,j), MX),//mx value unchanged
}else{//a[i][j]===1, at this time h (i,j) = 0, there is no sub-matrix containing (I,J)
mx=j+1; L (i,j) = 1;
}
The recursive relationship of R (I,J)
Define MN to indicate the right position before 0, the initial value =n
if (a[i][j]==0) {
R (i,j) =min (Mn,r (I-1,J))
}else{
Mx=j-1; R (i,j) =n;
}
where L (i,j), R (I,j), H (i,j) can be compressed into one-dimensional arrays.
*/
1#include <cstdio>2#include <iostream>3 using namespacestd;4 Const intmaxn= .;5 intN,A[MAXN],L[MAXN],R[MAXN],H[MAXN];6 intMx,mn,ans;7 intMain ()8 {9scanf"%d",&n);Ten for(intCol=1; col<=n;col++) Onel[col]=r[col]=Col; A for(introw=1; row<=n;row++) - { -mx=1; mn=N; the for(intCol=1; col<=n;col++) - { -scanf"%d",&A[col]); - if(a[col]==0) +h[col]=h[col]+1; - Else +h[col]=0; A if(a[col]==1) atmx=col+1; - if(a[col]==0) -l[col]=Max (L[COL],MX); - Else -l[col]=1; - } in for(intCol=n;col>0; col--) - { to if(a[col]==1) +mn=col-1; - if(a[col]==0) ther[col]=min (r[col],mn); * Else $r[col]=N;Panax NotoginsengAns=max (ans,h[col]* (r[col]-l[col]+1)); - } the } +printf"%d\n", ans); A return 0; the}
1159 Maximum full 0 sub-matrices