1387 Largest square

Source: Internet
Author: User

Difficulty: popularity/improvement-

Topic Type: Dynamic regulation

Number of submissions: 1

Related knowledge: Multidimensional dynamic regulation

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

Code:

1#include <iostream>2 using namespacestd;3 intd[ the][ the];4 intMinn (intAintBintc) {5     returnmin (A, min (b, c));6 }7 intMain () {8     intN;9Cin>>N;Ten     intI, J; One      for(i =1; I <= N; i++) A          for(j =1; J <= N; J + +) -Cin>>D[i][j]; -     intMaxx =0; the      for(i =1; I <= N; i++){ -          for(j =1; J <= N; J + +){ -             if(D[i][j] = =1){ -D[I][J] = Minn (d[i-1][J], d[i][j-1], d[i-1][j-1])+1; +Maxx =Max (Maxx, D[i][j]); -             } +         } A     } atcout<<Maxx; -     return 0; -}

Note:

D[i][j] represents the edge length of the largest square in the lower right corner (I,J). State transfer Equation D[i][j]=min (d[i-1][j],d[i][j-1],d[i-1][j-1]) (if d[i][j]==1). This truth is obvious, but it is not so taken for granted, in short, quite wonderful. This is a typical problem.

1387 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.