Title: For a 01 matrix, the largest of all is 1 rectangular area, the column can be arbitrarily interchangeable.
Analysis: DP. zoj2180 similar problem, calculate the maximum value of the first k rows, first by the height of the order.
Here, the query algorithm is optimized by the monotone queue, and the first point on the right (left) edge of each point is smaller than the one.
That is, to preserve the minimum height of an interval;
The largest area is max (minimum height * interval length),T (n) = n^2 log (n).
Description: (2011-09-19-08:10).
#include <stdio.h> #include <stdlib.h> #include <string.h>char maps[1005 [1005];int d[1005];int s[ 1005];int l[1005];int r[1005];int smq[1005];int cmp (const void* A, const void* b) {return * ((int *) a)-* ( (int *) b);} int main () {int n,m; while (~SCANF ("%d%d", &n,&m)) {for (int i = 1; I <= n; + + i) scanf ("%s", &maps[I [ 1]); memset (d, 0, sizeof (d)); int Max = 0; for (int i = 1; I <= n; + + i) {for (int j = 1; j <= m; + + j) {if (maps[i] [j] = = ' 1 ') + + d[j]; else d[J] = 0; s[J] = d[J]; } qsort (&s[1], M, sizeof (int), CMP); s[0] = s[m+1] =-1; /* for (int j = 1; j <= m; + + j) printf ("%d", s[J]); printf ("\ n"); */smq[0] = 0; IntTAIL1 = 0; for (int j = 1; J <= M+1; + + j) {while (s[smq[Tail1] > s[j]) r[SMQ [Tail1--]] = J; smq[+ + Tail1] = j; } smq[0] = m+1; int tail2 = 0; for (int j = m; J >= 0,---J) {while (s[smq[Tail2] > s[j]) l[smq[ TAIL2--]] = j; smq[+ + Tail2] = j; } for (int j = 1; j <= m; + + j) if (Max < s[J]* (r[J]-l[J]-1)) Max = s[J]* (r[J]-l[J]-1); } printf ("%d\n", Max); } return 0;}
HDU 2830-matrix Swapping II