Title: Give a matrix formed by 01, ask the matrix of the largest area of the square and the rectangle, any one of the squares adjacent to a different lattice.
Idea: In fact, all (i + j) &1 in the position of the number XOR, it becomes all 0 or 1 of the largest squares and rectangles. The first question is water DP, the second question can be monotonic stack or hanging line. are very well written.
CODE:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 2010using namespace Std;int m,n;int src[max][max];int f[max][max];int Up[max][max],_left[max][max],_right[max][max]; int main () {cin >> m >> n;for (int i = 1; I <= m; ++i) for (int j = 1; j <= N; ++j) {scanf ("%d", &src[i][ j]); if ((i + j) &1) src[i][j] ^= 1;} int ans = 0;for (int i = 1; I <= m; ++i) for (int j = 1; j <= N; ++j) if (Src[i][j]) {f[i][j] = min (F[i-1][j-1],min (f [I-1] [j],f[i][j-1]) + 1;ans = max (Ans,f[i][j]);} memset (F,0,sizeof (f)); for (int i = 1, i <= m; ++i) for (int j = 1; j <= N; ++j) if (!src[i][j]) {f[i][j] = min (f[i-1][j -1],min (F[i-1][j],f[i][j-1]) + 1;ans = max (Ans,f[i][j]);} cout << ans * ans << endl;ans = 0;for (int i = 1; I <= m; ++i) {for (int j = 1; j <= N; ++j) _left[i][j] = SRC[I][J]? _left[i][j-1] + 1:0;for (int j = n; j;--j) _right[i][j] = Src[i][j]? _right[i][j + 1] + 1:0;} for (int i = 1; I <= m; ++i) for (int j = 1; j <= N; ++j) if (Src[i][j] && src[i-1][j]) {up[i][j] = Up[i-1][j] + 1;_left[i][j] = min (_ LEFT[I][J],_LEFT[I-1][J]); _right[i][j] = min (_right[i][j],_right[i-1][j]); ans = max (ans, (_left[i][j] + _right[i][j)- 1) * (Up[i][j] + 1));} memset (_left,0,sizeof (_left)), memset (_right,0,sizeof (_right)), memset (up,0,sizeof (UP)), for (int i = 1; I <= m; ++i) { for (int j = 1; j <= N; ++j) _left[i][j] = Src[i][j]? 0:_left[i][j-1] + 1;for (int j = n; j;--j) _right[i][j] = Src[i][j]? 0:_right[i][j + 1] + 1;} for (int i = 1, i <= m; ++i) for (int j = 1; j <= N; ++j) if (!src[i][j] &&!src[i-1][j]) {up[i][j] = up[i-1] [j] + 1;_left[i][j] = min (_left[i][j],_left[i-1][j]); _right[i][j] = min (_right[i][j],_right[i-1][j]); ans = max (ans, (_l EFT[I][J] + _right[i][j]-1) * (Up[i][j] + 1));} cout << ans << endl;return 0;}
Bzoj 1057 Zjoi 2007 checkerboard Production dp+ Hanging line method