HDU 2830 Matrix Swapping II

Source: Internet
Author: User

Enumerate all rows. Then, for each row, record the number of 1 consecutive columns until this row. we can regard each column as 1 in width,

The continuous number is regarded as its height.

Then the problem can be seen as finding the largest rectangle in some adjacent rectangles with a height of 0, that is, the largest rectangle (HDU 1506)

It should be noted that the column can be arbitrarily moved, then the order of height from large to small is the optimal solution, and then B [I-1]> = B [I],

The area is obviously h [I] * I. Then enumeration.

[Cpp]
# Include <cstdio>
# Include <iostream>
# Include <cstring>
# Include <algorithm>
Using namespace std;
Int a [1010], B [1010];
Bool cmp (int t1, int t2)
{
Return t1> t2;
}
Int main ()
{
Int I, j, n, m, len, ans;
Char ch [1001];
While (scanf ("% d", & n, & m )! = EOF)
{
Memset (a, 0, sizeof ());
Ans = 0;
For (I = 1; I <= n; I ++)
{
Scanf ("% s", ch );
Len = strlen (ch );
For (j = 0; j <len; j ++)
{
If (ch [j] = '1 ')
A [j + 1] ++;
Else a [j + 1] = 0;
B [j + 1] = a [j + 1];
}
Sort (B + 1, B + 1 + m, cmp );
For (j = 1; j <= m & B [j]; j ++)
If (B [j] * j> ans) ans = B [j] * j;

}
Printf ("% d \ n", ans );
}
Return 0;
}

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.