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.
Source
Test instructions: A column of moving graphs, asking the largest 1-component area?
Idea: In each row, the high order, high is a "I", long is I, I code is J, and then you can find the best solution
</pre><pre name= "code" class= "CPP" > #include <iostream> #include <cstdio> #include < Algorithm> #include <cstring>using namespace std; #define N 1005int h[n],a[n];int n,m;int cmp (int a,int b) { return A>b;} int main () { int i,j; char c; while (~SCANF ("%d%d", &n,&m)) { getchar (); memset (h,0,sizeof (h)); int ans=0; for (i=1;i<=n;i++) { for (j=1;j<=m;j++) { scanf ("%c", &c); if (c== ' 1 ') h[j]++; else h[j]=0; } GetChar (); for (j=1;j<=m;j++) a[j]=h[j]; Sort (a+1,a+m+1,cmp); Emphasis once, is a column of a column of move for (j=1;j<=m;j++) Ans=max (ans,a[j]*j); } printf ("%d\n", ans); } return 0;}
HDu 2830 Matrix swapping II (DP)