https://vijos.org/p/1057
设f[i][j]为以i,j为正方形右下顶点的最大边长
不难得出初始值 f[i][j] = a[i][j] ,a为输入数组
则有状态转移方程 f[i][j] = min(f[i-1][j], f[i-1][j-1], f[i][j-1]);
因为f[i][j]只能从这些点得出
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cstdlib>
#define ms(i,j) memset(i,j,sizeof(i));
using namespace std;
/*
设f[i][j]为以i,j为正方形右下顶点的最大边长
不难得出初始值 f[i][j] = a[i][j] ,a为输入数组
则有状态转移方程 f[i][j] = min(f[i-1][j], f[i-1][j-1], f[i][j-1]);
因为f[i][j]只能从这些点得出
*/
int f[1005][1005];
int a[1005][1005];
int main()
{
int n,m;
scanf("%d%d", &n, &m);
for (int i=0;i<n;i++)
for (int j=0;j<m;j++)
{
scanf("%d", &a[i][j]);
f[i][j] = a[i][j];
}
int ans = -10;//有可能会整幅图都是瑕疵
for (int i=0;i<n;i++)
for (int j=0;j<m;j++)
if (a[i][j]==1)
{
f[i][j] = min(min(f[i-1][j], f[i][j-1]), f[i-1][j-1])+1;
ans = max(f[i][j], ans);
}
printf("%d\n", ans);
return 0;
}