Main topic:
The given matrix can be exchanged arbitrarily between each column.
Find out the largest sub-matrices and the obtained after swapping.
Thinking Analysis:
HEIGHT[I][J] Indicates how much depth the position I j is down.
Then we enumerate each row.
You can sort all the height.
Get the largest matrix and pass it over again.
N*n*lgn ...
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #define MAXN 1005using namespace Std;int Height[maxn][maxn];char p[maxn][maxn];int a[maxn];int Main () { int n,m; while (scanf ("%d%d", &n,&m)!=eof) {for (int i=0;i<n;i++) scanf ("%s", P[i]); for (int j=0;j<m;j++) { int now=0; for (int i=n-1;i>=0;i--) { if (p[i][j]== ' 1 ') now++; else now=0; Height[i][j]=now; } } int ans=0; for (int. i=0;i<n;i++) {for (int j=0;j<m;j++) a[j]=height[i][j]; Sort (a,a+m); int st=0; while (a[st]==0) st++; for (int j=st;j<m;j++) Ans=max (ans,a[j]* (m-j)); } printf ("%d\n", ans); } return 0;}