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