Bzoj 1057: [ZJOI2007] Checkerboard Production (DP + suspension method)

Source: Internet
Author: User

For the first question, the simple DP. F (i, j) is denoted by (I, j) as the largest square in the upper left corner, F (i, j) = min (f (i + 1, j), F (i, J + 1), f (i + 1, j + 1) + 1 (if (I, j) and right and bottom do not conflict)

The second question is the classic suspension method to solve the maximum sub-matrix, maintenance of the suspension line H[i][j], the left to the right extend the longest distance. First line of the line to find the L, R, and then swipe down from the top, maintain h, L, R

After writing, I found my brain is dead. The largest square must be in the largest sub-matrix Ah ... So I don't really need DP.

---------------------------------------------------------------------

#include <bits/stdc++.h>using namespace std;const int MAXN =; int N, M, MP[MAXN][MAXN], D[MAXN][MAXN], H[MAXN][MAXN], L[MAXN][MAXN], R[MAXN][MAXN];void Read () {cin >> N >> M;for (int i = 0; i < N; i++)For (int j = 0; J < M; J + +)scanf ("%d", &mp[i][j]);}void dp () {int ans = 1;for (int i = 0; i < N; i++) d[i][m-1] = 1;for (int i = 0; i < M; i++) d[n-1][i] = 1;for (int i = N-2; ~i; i--)For (int j = M-2; ~j; j--)if ((Mp[i][j] ^ mp[i + 1][j]) && (Mp[i][j] ^ mp[i][j + 1]) &&! ( MP[I][J] ^ Mp[i + 1][j + 1]))ans = max (ans, d[i][j] = min (d[i + 1][j + 1], min (d[i][j + 1], D[i + 1][j])) + 1);ElseD[i][j] = 1;cout << ans * ans << "\ n";}void Line () {for (int i = 0; i < N; i++) {l[i][0] = 0;For (int j = 1; j < M; J + +)L[i][j] = (L[i][j-1] + 1) * (Mp[i][j] ^ mp[i][j-1]);r[i][m-1] = 0;For (int j = M-2; ~j; j--)R[i][j] = (r[i][j + 1] + 1) * (Mp[i][j] ^ mp[i][j + 1]);}for (int i = 0; i < M; i++) h[0][i] = 1;for (int i = 1; i < N; i++)For (int j = 0; J < M; J + +)if (mp[i][j] ^ mp[i-1][j]) {H[i][j] = h[i-1][j] + 1;L[i][j] = min (L[i-1][j], l[i][j]);R[i][j] = min (R[i-1][j], r[i][j]);} elseH[i][j] = 1;int ans = 0;for (int i = 0; i < N; i++)For (int j = 0; J < M; J + +)ans = max (ans, h[i][j] * (R[i][j] + l[i][j] + 1));cout << ans << "\ n";} int main () {Read ();DP ();Line ();return 0;}

---------------------------------------------------------------------

1057: [ZJOI2007] Board making Time Limit:Sec Memory Limit:162 MB
Submit:1733 Solved:882
[Submit] [Status] [Discuss] Description

Chess is one of the oldest game games in the world, with Chinese Weiqi, chess and Japanese chess. It is said that chess originated from the thought of the I Ching, the chessboard is a 8*8 size of black and white square, corresponding to 8,864 gua, black and white corresponding yin and yang. And our protagonist, the little Q, is a chess enthusiast. As a top-notch player, he was not content with the usual chessboard and rules, so he and his good friend, Little W, decided to expand the chessboard to fit their new rules. Little Q found a rectangular piece of paper made up of squares of n*m, each of which was painted with one of the two colors of black and white. Little Q wanted to cut some of this paper as a new chessboard, and of course he wanted the chessboard to be as big as possible. But little Q has not decided to find a square chessboard or a rectangular chessboard (of course, the chessboard must be black and white, that is, the adjacent lattice is different), so he hopes to find the largest square checkerboard area and the largest rectangular checkerboard area, which will determine which is better. So little Q found the upcoming National Information Science Competition you, can you help him?

Input

The first line contains two integers n and m, each representing the length and width of the rectangular paper. The next n rows contain a 01 matrix of N * m, representing the color of the rectangle paper (0 for White and 1 for black).

Output

Contains two lines, each containing an integer. The first behavior can be found in the area of the largest square checkerboard, and the second behavior can be found in the area of the largest rectangular checkerboard (note that squares and rectangles can intersect or contain).

Sample Input 3 3
1 0 1
0 1 0
1 0 0Sample Output 4
6HINT

For 100% of data, N, m≤2000

Source

Bzoj 1057: [ZJOI2007] Checkerboard Production (DP + suspension method)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.