Problem Descriptiongiven an N * M matrix with each entry equal to 0 or 1. We can find some rectangles in the matrix whose entries is all 1, and we define the maximum area of such rectangle as thi S matrix ' s goodness.
We can swap any or both columns any times, and we is to make the goodness of the matrix as large as possible.
Inputthere is several test cases in the input. The first line of all test case contains, integers N and M (1≤n,m≤1000). Then n lines follow, each contains m numbers (0 or 1), indicating the n * M Matrix
Outputoutput one line for each test case, indicating the maximum possible goodness.
Sample Input
3 41011100100013 4101010010001
Sample Output
42note:huge Input, scanf () is recommended.
Practice Reference Online, the number of consecutive records of each row, after the DP can be sorted. Stealing a picture
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < Limits.h>using namespace Std;int N,m;char str[1100];int num[1100],sum[1100];int cmp (int a,int b) { return a>b;} int main () { while (~scanf ("%d%d", &n,&m)) { getchar (); char ch; int ans=0; memset (num,0,sizeof (num)); for (int i=1;i<=n;i++) { for (int j=1;j<=m;j++) { scanf ("%c", &ch); if (ch== ' 1 ') num[j]++; else num[j]=0; SUM[J]=NUM[J]; } Sort (sum+1,sum+m+1,cmp); for (int i=1;i<=m;i++) Ans=max (ans,sum[i]*i); GetChar (); } printf ("%d\n", ans); } return 0;}