[Luo gu 1387] the largest square

Source: Internet
Author: User

Title Description

In a n*m-only matrix containing 0 and 1, find a maximum square that does not contain 0, and the output edge length.

Input/output format

Input format:

The first behavior of the input file is two integers n,m (1<=n,m<=100), followed by n lines, with m numbers per line, separated by spaces, 0 or 1.

Output format:

An integer, the edge length of the largest square

Input/Output sample

Input Sample # #:

4 40 1 1 11 1 1 00 1 1 01 1 0 1

Sample # # of output:

2
Ideas

DP,F[I,J] Indicates the square size with i,j as the rightmost bottom point.

F[i,j]:=min (min (f[i-1,j],f[i,j-1]), f[i-1,j-1]) +1

varA,f:Array[0.. +,0.. +] ofLongint;    N,m,i,j,ans:longint; functionMax (x,y:longint): Longint; begin      ifX>y ThenExit (x)Elseexit (y); End; functionmin (x,y:longint): Longint; begin      ifX>y ThenExit (Y)Elseexit (x); End; beginFillchar (A,sizeof (a),0); Fillchar (F,sizeof (f),0);      READLN (N,M);  fori:=1  toN Do           forj:=1  toM Doread (a[i,j]);  fori:=1  toN Do           forj:=1  toM Do              ifa[i,j]=1  ThenF[i,j]:=min (min (f[i-1, j],f[i,j-1]), f[i-1, J-1])+1;  fori:=1  toN Do           forj:=1  toM Doans:=Max (ans,f[i,j]);  Writeln (ANS); End.
View Code

[Luo gu 1387] the largest square

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.