Test instructions gives you a n*m matrix. Each column can be exchanged freely to find the maximum 1 sub-matrices of the optimal switching position.
It's a variant of the HDU 1505 1506, but it's easier because each column can be swapped for a position. So all of this line is higher than I can be adjacent to I only need to count this line how many more than I line can be calculated after each row to put the height of the front to use Num[i] records sorted Column The original number so that there is a J column than H[i][num[j]] higher the final answer is Max (J*h[i][num[j])
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int N = 1005;char Mat N [N];int Num[n], h[n][n], N, M, i;bool cmp (int a, int b) { return h[i][a] > H[i][b];} CMP cannot have =int main () {while (~scanf ("%d%d", &n, &m)) { int ans = 0; memset (h, 0, sizeof (h)); for (i = 1; I <= n; ++i) scanf ("%s", Mat[i] + 1); for (i = 1; I <= N, ++i) {for (int j = 1; j <= m; ++j) { if (mat[i][j] = = ' 1 ') h[i][j] = h[i -1][J] + 1; NUM[J] = j; } Sort (num + 1, num + M + 1, CMP); for (int j = 1; j <= m; ++j) ans = max (ans, J * H[i][num[j]); } printf ("%d\n", ans); } return 0;}
Matrix swapping IIproblem 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.