"BZOJ3039" Jade Toad Hall/"HDU1505" "POJ1964" City Game maximum 01 sub-matrix

Source: Internet
Author: User

Reprint Please specify source: http://blog.csdn.net/vmurder/article/details/42884845

First we can use a monotone stack to sweep through each row, maintain a point to the top and bottom of each can extend how long.

Of course, this can be done, is also very disgusting.


We can sweep through each line to maintain the maximum left-to-right distance at the current [column height] of each point.

Of course, a certain point can be lowered a little bit, it will be wider, the result is better, but obviously since there is such a result, then the other columns must be able to do.


Uh. So sweep through each line, and then record the maximum distance that each node in the line can extend to the left and right at the maximum height.

The thought of this problem can be done with a monotonous stack, but I have written a thing like prefix and or interval covering and looking up a set or something.


Ah, it looks like a while loop, but it can be linear ~. Well, the averaging analysis of the global analysis of God Horse.

The algorithm is based on the idea of continuous extension.

How to say, is the current height of each point has a left/right extension distance, and since this point satisfies, then this paragraph also must satisfy

(A<=b b<=c a<=c)

Then skip this section and check the next paragraph.

Do not analyze each need a few times, to analyze each of the other contributions, and then casually yy can be proven linear.


Code:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 1010using namespace Std;char s[3];int d[n],l[n],r[n];int n,m,ans;int main () {int i,j,k;memset (d,0,sizeof D); scanf ("%d%d ", &n,&m); for (i=1;i<=n;i++) {for (j=1;j<=m;j++) {l[j]=r[j]=j;scanf ("%s ", s), if (s[0]== ' F ') D[j]++;else D [J]=0;} for (j=1;j<=m;j++) if (D[j]) while (D[j]<=d[l[j]-1]) l[j]=l[l[j]-1];for (j=m;j>=1;j--) if (D[j]) while (d[j]< =D[R[J]+1]) r[j]=r[r[j]+1];for (j=1;j<=m;j++) Ans=max (ans, (r[j]-l[j]+1) *d[j]);} printf ("%d\n", ans*3); return 0;}


"BZOJ3039" Jade Toad Hall/"HDU1505" "POJ1964" City Game maximum 01 sub-matrix

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.