"BZOJ1057" "ZJOI2007" checkerboard making up to 01 sub-matrices/squares

Source: Internet
Author: User

Reprint Please specify the source Thank you: http://blog.csdn.net/vmurder/article/details/42886393

Exercises

Well, this picture is really not very good to do,

But we can convert it to perfection is a 1/0 sub-matrix problem.

is to reverse the point 01 of the same row parity, and then it's OK (this is obviously, need to prove the message).

And then we're asking for the maximum sub-matrix.

As for the square? To seek the sub-matrix by the way, that is the ans1,

This is obviously because we enumerate the ductility of each point, so we don't miss out on any possibility.

So let's say that if a square is not considered, its length or width must be a maximum value, then it will definitely appear in one of our calculated rectangles!


And then how to find the maximum 01 sub-matrices See previous blog http://blog.csdn.net/vmurder/article/details/42884845

Code:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 2020# Define INF 0x3f3f3f3fusing namespace Std;int map[n][n];int l[n],r[n],d[n];int n,m,ans1,ans2;int Main () {Freopen (" Test.in "," R ", stdin), int i,j,k,t;scanf ("%d%d ", &n,&m), for (i=1;i<=n;i++) for (j=1;j<=m;j++) {scanf ("%d " , &map[i][j]); if ((i+j&1) ==0) map[i][j]= (!map[i][j]);} D[0]=d[m+1]=0;for (i=1;i<=n;i++) {for (j=1;j<=m;j++) {l[j]=r[j]=j;if (map[i][j]) D[j]++;else d[j]=0;} for (j=1;j<=m;j++) if (D[j]) while (D[l[j]-1]>=d[j]) l[j]=l[l[j]-1];for (j=m;j>=1;j--) if (D[j]) while (d[r[j]+1 ]&GT;=D[J]) r[j]=r[r[j]+1];for (j=1;j<=m;j++) {k=r[j]-l[j]+1;t=min (k,d[j]); Ans1=max (ans1,t*t); Ans2=max (ans2,k* D[J]);}} memset (d,0,sizeof D); for (i=1;i<=n;i++) {for (j=1;j<=m;j++) {l[j]=r[j]=j;if (!map[i][j]) D[j]++;else d[j]=0;} for (j=1;j<=m;j++) if (D[j]) while (D[l[j]-1]>=d[j]) l[j]=l[l[j]-1];for (j=m;j>=1;j--) if (D[j]) while (d[r[j]+1 ]&GT;=D[J]) r[j]=r[r[j]+1];for (j=1;j<=m;j++) {k=r[j]-l[J]+1;t=min (K,d[j]); Ans1=max (ans1,t*t); Ans2=max (Ans2,k*d[j]);}} printf ("%d\n%d\n", ans1,ans2); return 0;}


"BZOJ1057" "ZJOI2007" checkerboard making up to 01 sub-matrices/squares

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.