CF260--C -- dp <maximum discontinuous subsequence and>

Source: Internet
Author: User

Ah... I didn't do the CF this time. =-= that night, my computer suddenly became nervous and various web pages opened slowly...

What's worse is that it lasted for more than an hour. I want to reinstall it... MD can access the slot again *******

But unfortunately, at that time, it was just getting started.

Touch me

Today, I went to see the largest discontinuous subsequence I made a few days ago and I also mentioned it in particular =-=

Sad ....

  

 1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 using namespace std; 5  6 typedef long long LL; 7 const int size = 100000; 8 LL cnt[size]; 9 LL dp[size];10 11 int main()12 {13     int n , num , mmax;14     LL ans;15     while( cin >> n )16     {17         memset( cnt , 0 , sizeof(cnt) );18         mmax = 0;19         for( int i = 1 ; i<=n ; i++ )20         {21             cin >> num;22             cnt[ num ] ++;23             if( mmax < num )24                 mmax = num;25         }26         dp[1] = cnt[1]*1;27         dp[2] = cnt[2]*2;28         ans = max( dp[1] , dp[2] );29         for( int i = 3 ; i<=mmax ; i++ )30         {31             dp[i] = max( dp[i-2] , dp[i-3] ) + cnt[i]*i;32             if( ans < dp[i] )33                 ans = dp[i];34         }35         cout << ans << endl;36     }37     return 0;38 }
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.