HDU 2830 Matrix Swapping II (amount, sort?) )

Source: Internet
Author: User

Test instructions

The matrix of N*m, not 0 in each lattice is 1.

You can swap a couple of columns arbitrarily. Finally, a new matrix is obtained.

Ask what is the largest sub-rectangular area that can be obtained (this sub-rectangle must be all 1).

Ideas:

First, A[i][j] records the number of consecutive 0 from the column I, section J.

Enumerate each row as the bottom of the sub-matrix of the answer, and then sort the line a[i][j] from large to small, sweeping through the calculations.

Look at the code.

Code:

intn,m;Chartemps[1005][1005];inta[1005][1005]; intts[1005];BOOLcmpintAintb) {    returnA>b;}intMain () { while(SCANF ("%d%d", &n,&m)! =EOF) {Rep (i,0, N-1) {scanf ("%s", Temps[i]); } mem (A,0); Rep (I,0, M-1)if(temps[0][i]=='0') a[0][i]=0;Elsea[0][i]=1; Rep (I,1, N-1) {Rep (J,0, M-1){                if(temps[i][j]=='1') a[i][j]=1+a[i-1][j]; }        }        intans=0; Rep (I,0, N-1) {Rep (J,0, M-1) ts[j]=A[i][j]; Sort (Ts,ts+m,cmp); Rep (I,0, M-1) Ans=max (ans,ts[i]* (i+1) ); } printf ("%d\n", ans); }    return 0;}

HDU 2830 Matrix Swapping II (amount, sort?) )

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.