HDU -- 2830 -- matrix of any swap Column

Source: Internet
Author: User

What we do in the past two days is related to the matrix =-= ....

There are so many flowers in the small matrix...

This topic features that we can swap any two columns any times can be arbitrarily exchanged between column X and column Y at any time.

At first, I was worried that my method would not be able to see Ms... I always think there will be a more efficient method, but I did not expect it

My idea is to assume that the height of column Y in row X is 3 4 5 2 3 6

If the height is greater than or equal to 2, 6 to 0 columns in total. 0 can be regarded as (CNT [0] + CNT [1]). for the sum, you can assume that we have also placed 0 columns with a height of 0 and 1.

Similarly, the height> = 3 is 6-1...

So I am using this method for computation. It is quite simple to have some details, just pay attention to the processing. For example, the CNT [] array should be reset to 0 in each row because the H [] array in each row all are changing.

-------------- Actually not that nice =-= I have hidden the code first. If I haven't done it now, I can check it out ~

 1 #include <iostream> 2 using namespace std; 3  4 const int size = 1010; 5 char str[size]; 6 int h[size]; 7 int cnt[size]; 8  9 int main()10 {11     cin.sync_with_stdio(false);12     int n , m , ans , sum , maxH , area;13     while( cin >> n >> m )14     {15         memset( cnt , 0 , sizeof(cnt) );16         memset( h , 0 , sizeof(h) );17         ans = 0;18         for( int i = 1 ; i<=n ; i++ )19         {20             maxH = sum = 0;21             cin >> str;22             for( int j = 0 ; str[j]!=‘\0‘ ; j++ )23             {24                 if( str[j]==‘1‘ )25                     h[j+1] ++;26                 else27                     h[j+1] = 0;28                 cnt[ h[j+1] ] ++;29                 if( maxH < h[j+1] )30                     maxH = h[j+1];            31             }32             for( int k = 0 ; k<=maxH ; k++ )33             {34                 if( cnt[k]!=0 )35                 {36                     area = k * (m-sum);37                     sum += cnt[k];38                     if( area>ans )39                         ans = area;40                 }41                 cnt[k] = 0;42             }43         }44         cout << ans << endl;45     }46     return 0;47 }
View code

 

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.