POJ3493 largest submatrix of all 1 ' s (monotone stacks)

Source: Internet
Author: User

The topic gives a 01 matrix, which asks for the largest 1 sub-matrices.

With DP preprocessing the 1 of each column of each row can be extended up by a continuous number of 1, and then enumerate each row as the bottom of the sub-matrix, so the answer to each row is POJ2559 this classic question.

1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 #defineMAXN 22226 intSTACK[MAXN],TOP,L[MAXN],R[MAXN];7 intCalcint*a,intN) {8a[++n]=-1; top=0;9      for(intI=1; i<=n; ++i) {Tenl[i]=r[i]=i; One          while(Top && a[stack[top]]>A[i]) { Ar[stack[top]]=i-1; -l[i]=L[stack[top]]; ---top; the         } -         if(Top && a[stack[top]]==a[i]) l[i]=L[stack[top]]; -stack[++top]=i; -     } +     intres=0; -      for(intI=1; i<n; ++i) { +Res=max (res,a[i]* (r[i]-l[i]+1)); A     } at     returnRes; - } - intD[MAXN][MAXN]; - intMain () { -     intn,m; -      while(~SCANF ("%d%d",&n,&m)) { in          for(intI=1; i<=n; ++i) { -              for(intj=1; j<=m; ++J) scanf ("%d",&d[i][j]); to         } +          for(intI=1; i<=n; ++i) { -              for(intj=1; j<=m; ++j) { the                 if(D[i][j]) d[i][j]=d[i-1][j]+1; *             } $         }Panax Notoginseng         intres=0; -          for(intI=1; i<=n; ++i) { theRes=max (Res,calc (&d[i][0],m)); +         } Aprintf"%d\n", res); the     } +     return 0; -}

POJ3493 largest submatrix of all 1 ' s (monotone stacks)

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.