Bzoj 3039: Jade Toad Hall (suspension line method)

Source: Internet
Author: User

Maximum sub-matrix ... Suspension Line Method: Time complexity O (nm) http://blog.csdn.net/wzq_qwq/article/details/47167707

The method of suspension is to record the maximum length of an h extension (hanging line), L, R to the left to the right to extend the maximum length, and then by recursion to get.

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

#include <bits/stdc++.h>using namespace std;#define OK (c) ((c) = = ' F ' | | (c) = = ' R ')const int MAXN = 1009; int H[MAXN][MAXN], L[MAXN][MAXN], R[MAXN][MAXN], N, M;bool F[MAXN][MAXN];void Read () {cin >> N >> M;for (int i = 0; i < N; i++)For (int j = 0; J < M; J + +) {char C = getchar ();For (;!ok (c); c = GetChar ());F[i][j] = c = = ' F ';    }}int main () {Read ();for (int i = 0; i < N; i++) {l[i][0] = f[i][0];For (int j = 1; j < M; J + +)L[i][j] = f[i][j]? L[i][j-1] + 1:0;r[i][m-1] = f[i][m-1];For (int j = M-2; ~j; j--)R[i][j] = f[i][j]? R[i][j + 1] + 1:0;}memset (h, 0, sizeof h);for (int i = 1; i < N; i++)For (int j = 0; J < M; J + +) if (F[i][j] && f[i-1][j]) {H[i][j] = h[i-1][j] + 1;L[i][j] = min (L[i][j], l[i-1][j]);R[i][j] = min (R[i][j], r[i-1][j]);}int ans = 0;for (int i = 0; i < N; i++)For (int j = 0; J < M; J + +) if (F[i][j])ans = max (ans, (h[i][j] + 1) * (L[i][j] + r[i][j]-1));cout << 3 * ans << "\ n";return 0;}

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

Bzoj 3039: Jade Toad Hall (suspension line 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.