HDU 2830 Matrix Swapping II (DP, max full 1 matrix)

Source: Internet
Author: User

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.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.