#C9509. Largest Square Sub-grid
Largest Square Sub-grid
Largest Square Sub-grid
You are given a binary grid with M rows and N columns. The grid contains only characters '0' and '1'. Your task is to determine the side length of the largest square sub-grid consisting entirely of '1's for each test case.
To solve this problem, you can use dynamic programming. Let dp[i][j] represent the side length of the largest square whose bottom-right corner is at cell (i, j). If grid[i][j] is '1', then
[ dp[i][j] = \min{dp[i-1][j],\ dp[i][j-1],\ dp[i-1][j-1]} + 1 ]
Otherwise, dp[i][j] is 0. The answer for a test case is the maximum value in the dp table.
inputFormat
The first line of the input contains an integer T (T ≥ 1) denoting the number of test cases. For each test case, the first line contains two space-separated integers, M and N, representing the number of rows and columns. The next M lines each contain a string of length N representing the binary grid.
Input is provided via standard input (stdin).
outputFormat
For each test case, output a single integer on a new line representing the side length of the largest square sub-grid composed entirely of '1's. The output should be written to standard output (stdout).
## sample3
4 5
11110
11010
11000
00000
3 3
101
111
111
2 2
01
10
2
2
1
</p>