BZOJ 1057. [ZJOI2007] board production

 

The parity, the x, y coordinates add up to an odd number of inverted bit position, seeking to become a maximum 01 sub-matrix.

Then the pre-up position of each longest path 01, each line with a monotonous stack solution.

Monotone maintenance stack height and width of each matrix from the stack to the bottom of the stack, by increasing height maintenance.

If the current height is less than the height of the top of the stack, it will update the answer to the width of the matrix, and the stack, but its width is to contribute to the current height of the matrix, is the current matrix stack to join the top of the stack have to add this should be a stack matrix.

The last one done after the re clear about the stack on the line.

#include <bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second

const int N = 2222;
int a[N][N], dp[N][N], n, m, ans1, ans2;
std::pii st[N];

void solve() {
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            dp[i][j] = (a[i][j] ? dp[i - 1][j] + 1 : 0);
    for (int i = 1; i <= n; i++) {
        int top = 0;
        for (int j = 1; j <= m + 1; j++) {
            int w = 0;
            while (top && st[top].fi > dp[i][j]) {
                int h = st[top].fi;
                w += st[top].se;
                top--;
                ans1 = std::max(ans1, std::min(w, h) * std::min(w, h));
                ans2 = std::max(ans2, w * h);
            }
            st[++top] = std::pii(dp[i][j], w + 1);
        }
    }
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            scanf("%d", a[i] + j);
            if ((i + j) % 2) a[i][j] ^= 1;
        }
    solve();
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            a[i][j] ^= 1;
    solve();
    printf("%d\n%d\n", ans1, ans2);
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/Mrzdtz220/p/12233343.html