Fshl0

248

May 23rd, 2021
760
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 300;
  6.  
  7. int rangeDP[N][N], A[N];
  8.  
  9. int main () {
  10.     freopen ("248.in", "r", stdin);
  11.     freopen ("248.out", "w", stdout);
  12.     int n, res = 0;
  13.     cin >> n;
  14.     for (int i = 1; i <= n; i++)
  15.         cin >> A[i];
  16.     for (int i = 1; i <= n; i++)
  17.         rangeDP[i][i] = A[i];
  18.     for (int len = 2; len <= n; len++) {
  19.         for (int i = 1; i + len - 1 <= n; i++) {
  20.             int j = i + len - 1;
  21.             for (int k = i; k < j; k++) {
  22.                 if (rangeDP[i][k] == rangeDP[k + 1][j])
  23.                     rangeDP[i][j] = max (rangeDP[i][j], rangeDP[i][k] + 1);
  24.             }
  25.             res = max (res, rangeDP[i][j]);
  26.         }
  27.     }
  28.     cout << res << "\n";
  29.     return 0;
  30. }
  31.  
RAW Paste Data