fork download
  1. int c[205], n, dp[203][203], nx[203];
  2. ll check(int x, int y) {
  3. if(x >= y) return 0;
  4. if(dp[x][y] != -1) return dp[x][y];
  5. int ans = (c[x] != c[x + 1]) + check(x + 1, y);
  6. for(int i = nx[x]; i <= y; i = nx[i]) {
  7. int temp = check(x + 1, i - 1) + 1 + check(i, y);
  8. ans = min(ans, temp);
  9. }
  10. return dp[x][y] = ans;
  11. }
  12. void solve()
  13. {
  14. cin >> n;
  15. for(int i = 0; i < n; i++) cin >> c[i];
  16. for(int i = 0; i < n; i++) {
  17. for(int j = 0; j < n; j++)
  18. dp[i][j] = -1;
  19. }
  20. vector<int> pre(n + 1, n);
  21. for(int i = n - 1; i >= 0; i--) {
  22. nx[i] = pre[c[i]];
  23. pre[c[i]] = i;
  24. }
  25. cout << check(0, n - 1) + 1 << '\n';
  26. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:1: error: ‘ll’ does not name a type
 ll check(int x, int y) {
 ^~
prog.cpp: In function ‘void solve()’:
prog.cpp:14:5: error: ‘cin’ was not declared in this scope
     cin >> n;
     ^~~
prog.cpp:20:5: error: ‘vector’ was not declared in this scope
     vector<int> pre(n + 1, n);
     ^~~~~~
prog.cpp:20:12: error: expected primary-expression before ‘int’
     vector<int> pre(n + 1, n);
            ^~~
prog.cpp:22:17: error: ‘pre’ was not declared in this scope
         nx[i] = pre[c[i]];
                 ^~~
prog.cpp:25:5: error: ‘cout’ was not declared in this scope
     cout << check(0, n - 1) + 1 << '\n';
     ^~~~
prog.cpp:25:13: error: ‘check’ was not declared in this scope
     cout << check(0, n - 1) + 1 << '\n';
             ^~~~~
stdout
Standard output is empty