Fshl0

Modern Art 3

May 24th, 2021
593
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 + 9;
  6.  
  7. int rangeDP[N][N], A[N];
  8.  
  9. int main () {
  10.     int n;
  11.     cin >> n;
  12.     for (int i = 1; i <= n; i++)
  13.         cin >> A[i];
  14.     for (int len = 2; len <= n; len++) {
  15.         for (int i = 1; i + len - 1 <= n; i++) {
  16.             int j = i + len - 1;
  17.             if (A[i] == A[j])
  18.                 rangeDP[i][j] = 1 + rangeDP[i + 1][j - 1];
  19.             for (int k = i + 1; k < j; k++)
  20.                 rangeDP[i][j] = max (rangeDP[i][j], rangeDP[i][k] + rangeDP[k][j]);
  21.         }
  22.     }
  23.     cout << n - rangeDP[1][n] << "\n";
  24.     return 0;
  25. }
  26.  
RAW Paste Data