Advertisement
Guest User

Untitled

a guest
May 30th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. int n;
  7. vector <int> a(5001,0);
  8. vector < vector <int> > x(5001,vector <int>(5001,0));
  9. vector <int> dp(5001,0);
  10. vector <int> first(5001,10e6);
  11. vector <int> last(5001,0);
  12.  
  13.  
  14.  
  15.  
  16. int cur(int left, int right)
  17. {
  18.  
  19.     int pff(0);
  20.  
  21.     for (int i=left;i<=right;i++)
  22.     {
  23.         for (int j=i;j<=right;j++)
  24.         {
  25.  
  26.             if (a[i]!=a[j])
  27.             {
  28.  
  29.  
  30.                 pff=max(pff,x[i][j]);
  31.                 //cout << x[i][j] << " ";
  32.             }
  33.             else{
  34.                 pff=max(pff,a[i]);
  35.                // cout << i << " ";
  36.             }
  37.             //cout << a[i] << " ";
  38.         }
  39.     }
  40.     return pff;
  41.  
  42. }
  43.  
  44. int main()
  45. {
  46.         ios::sync_with_stdio(0); cin.tie(0) ; cout.tie(0);
  47.  
  48.         #ifdef _DEBUG
  49.         cout << setprecision(6)  << fixed ;
  50.         #endif
  51.  
  52.  
  53.  
  54.         for (int i=1;i<=5000;i++)
  55.        {
  56.            for (int j=i+1;j<=5000;j++)
  57.            {
  58.                ll pf=i^j;
  59.                x[i][j]=pf;
  60.                x[j][i]=pf;
  61.            }
  62.        }
  63.         cin >> n;
  64.        for (int i=1;i<=n;i++)
  65.        {
  66.            cin >> a[i];
  67.            first[a[i]]=min(first[a[i]],i);
  68.            last[a[i]]=max(last[a[i]],i);
  69.  
  70.        }
  71.  
  72.  
  73.        //cout << cur (1 , 2);
  74.  
  75.  
  76.  
  77.        for (int i=1;i<=n;i++)
  78.        {
  79.            for (int j=i;j>=1;j--)
  80.            {
  81.  
  82.                     bool cheker=true;
  83.                     for (int z=j;z<=i and cheker==true;z++)
  84.                     {
  85.                         if (first[a[z]]>=j and last[a[z]]<=i)
  86.                         {
  87.  
  88.                         }
  89.                         else{
  90.                             cheker=false;
  91.                         }
  92.                         //cout << cheker << " " << i << " ";
  93.  
  94. ;                    }
  95.                     if (cheker)
  96.                     {
  97.                         dp[i]=max(dp[i],dp[j-1]+cur(i , j));
  98.                         //cout << cur(i , j) << "\n";
  99.  
  100.                     }
  101.                     else{
  102.                         dp[i]=max(dp[i],dp[i-1]);
  103.                     }
  104.  
  105.                     if (i==j and first[a[i]]==i and last[a[i]]==i)
  106.                     {
  107.                         dp[i]=max(dp[i] , a[i]);
  108.                     }
  109.  
  110.                     //cout << cur(i , j) << "\n" ;
  111.  
  112.  
  113.  
  114.            }
  115.  
  116.        }
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123. //cout << dp[n] << " ";
  124. /*for (int i=1;i<=n;i++)
  125. {
  126.     cout << first[i] <<" "  <<last[i] << "\n";
  127. }
  128. */
  129.         return 0;
  130.  
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement