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