P1387 Max Square P1736 Creative eating fish method
Two similar $dp$.
The transfer equation is basically similar to $f[i][j]=min (F[i-1][j-1],min (F[I][J-1],F[I-1][J)) $
Consider constituting a square ...
#include <bits/stdc++.h>using namespacestd;intn,m,a[ the][ the],ans=1, f[ the][ the];intMain () {CIN>>n>>m; for(intI=1; i<=n;i++) for(intj=1; j<=m;j++) {cin>>A[i][j]; if(a[i][j]==1) F[i][j]=min (f[i-1][j-1],min (f[i][j-1],f[i-1][J]) +1; Elsef[i][j]=0; Ans=Max (F[i][j],ans); } printf ("%d", ans); return 0;}
The preprocessing $s[i][j]$ indicates how many of the $i,j$ this point extends up to 0, and No 1;
$z [i][j]$ means $i,j$ this point to the left (or right) to extend the maximum number of 0, and No 1;
State transition equation: $f [I]][j]=min (F[i-1][j-1],min (S[i-1][j],z[i][j-1])) $ (top left to right)
Top right to bottom left like
#include <bits/stdc++.h>#defineN 2505using namespacestd;intA[n][n],s[n][n],z[n][n],n,m,f[n][n],ans;intMain () {scanf ("%d%d",&n,&m); for(intI=1; i<=n;i++) for(intj=1; j<=m;j++) {scanf ("%d",&A[i][j]); if(!A[i][j]) {S[i][j]=s[i-1][j]+1; Z[I][J]=z[i][j-1]+1; } ElseF[i][j]=min (f[i-1][j-1],min (s[i-1][j],z[i][j-1]))+1; Ans=Max (ans,f[i][j]); } memset (Z,0,sizeof(z)); Memset (F,0,sizeof(f)); for(intI=1; i<=n;i++) for(intj=m;j>=1; j--){ if(!A[i][j]) {Z[i][j]=z[i][j+1]+1; } ElseF[i][j]=min (f[i-1][j+1],min (s[i-1][j],z[i][j+1]))+1; Ans=Max (ans,f[i][j]); } printf ("%d\n", ans); return 0;}/*1 0 0 0 0 0 0 0 0 10 1 0 0 0 0 0 0 1 00 0 1 0 0 0 0 1 0 00 0 0 1 0 0 1 0 0 00 0 0 0 1 1 0 0 0 00 0 0 0 1 0 0 1 0 0 1 0 0 xx 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0*/
P1387 Max Square &&p1736 Creative eating fish method