About the biggest sub-matrix problem

See specific  Talking with the great idea of solving the biggest problem of sub-rectangular paper


In fact, I wanted to make it do monotonous stack, but happened to see the biggest sub-matrix problem, of course, can do with a stack monotonous, but I first learned the hanging line method, on the first stack monotonous after leaving pit

Little understood that my method of suspension wires, suspended line is defined on the endpoint covers an obstacle or point reaches the upper end of the outer ends of the rectangle except the whole vertical barriers do not include points, colloquially point is an obstacle to the top or to the top, does not include vertical barrier point, the first sub-matrix of any one of the greatest suspension contains at least one line, and the suspended lines to twice the maximum scan must contain sub-matrices. The question then is, how to find all of the suspension lines, due to the one-point suspension line and bottom (top point barrier for a suspension can have multiple lines), it can be achieved through the bottom of the enumeration.

Briefly about steps, which is pretreated

for (int i = 1; i <= n; i++)
        for (int j = 2; j <= m; j++) 
            if (map[i][j] == 1 && map[i][j - 1] == 1)   //两个都不是障碍,就扩展一下
                l[i][j] = l[i][j - 1];
    for (int i = 1; i <= n; i++)
        for (int j = m - 1; j >= 1; j--)
            if (map[i][j] == 1 && map[i][j + 1] == 1)
                r[i][j] = r[i][j + 1];

Core step

for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            if (map[i][j] == 1 && map[i - 1][j] == 1) {
                r[i][j] = min(r[i][j], r[i - 1][j]);
                l[i][j] = max(l[i][j], l[i - 1][j]);
                up[i][j] = up[i - 1][j] + 1;
            }
            ans = max(ans, (r[i][j] - l[i][j] + 1) * up[i][j]);
        }

 

Here is the topic

This is luogu4171 jade moon code, a board question

#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1010;
int map[N][N], l[N][N], r[N][N], up[N][N];
int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            char s[2];
            scanf("S% " , S);
             IF (S [ 0 ] == ' F. ' ) 
                Map [I] [J] = . 1 , L [I] [J] R & lt = [I] [J] = J;
             the else 
                Map [ I] [J] = 0 , L [I] [J] = . 1 , R & lt [I] [J] = 0 ; // note here, to ensure that this happens is below a length of about 0 
            up [I] [ J] = . 1 ; 
        } 
    for ( int I = . 1 ; I <= n-; I ++ )
         for ( int J = 2 ; J <= m; J ++) 
            if (map[i][j] == 1 && map[i][j - 1] == 1)
                l[i][j] = l[i][j - 1];
    for (int i = 1; i <= n; i++)
        for (int j = m - 1; j >= 1; j--)
            if (map[i][j] == 1 && map[i][j + 1] == 1)
                r[i][j] = r[i][j + 1];
    int ans = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            if (map[i][j] == 1 && map[i - 1][j] == 1) {
                r[i][j] = min(r[i][j], r[i - 1][j]);
                l[i][j] = max(l[i][j], l[i - 1][j]);
                up[i][j] = up[i - 1][j] + 1;
            }
            ans = max(ans, (r[i][j] - l[i][j] + 1) * up[i][j]);
        }
    printf("%d", ans * 3);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/cminus/p/12375506.html