#K71222. Largest Square Sub-Matrix of 1's
Largest Square Sub-Matrix of 1's
Largest Square Sub-Matrix of 1's
You are given a binary matrix with dimensions (n \times m) consisting of 0's and 1's. Your task is to determine the size of the largest square sub-matrix that contains only 1's.
The key idea is to use dynamic programming where you maintain a DP table (dp) such that
[
dp[i][j] = \min(dp[i-1][j],, dp[i][j-1],, dp[i-1][j-1]) + 1
]
if the current cell (matrix[i][j] = 1), and 0 otherwise. The answer is the maximum value in the DP table.
inputFormat
Input is read from standard input (stdin).
The first line contains two integers (n) and (m), representing the number of rows and columns of the matrix, respectively.
This is followed by (n) lines, each containing (m) space-separated integers (0 or 1) representing the matrix.
outputFormat
Output the size of the largest square sub-matrix consisting entirely of 1's to standard output (stdout).## sample
1 1
0
0