func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void read(_T &dig) {     int flg;     char c;     flg = dig = 0;     while (c = getchar(), !isdigit(c))       if (c ==  - ) flg = 1;     while (isdigit(c)) dig = dig * 10 + c -  0 , c = getchar();     if (flg) dig = -dig;   }   template <typename _T, typename... Args>   inline void read(_T &x, Args &...args) {     read(x);     read(args...);   }   const int N = 505, M = 1e5 + 5;   int n, f[N][N], a[N];   int head[M], nxt[M], tot, ver[M], v[N], in[N];   queue<int> q;   void add(int u, int v) { nxt[++tot] = head[u], head[u] = tot, ver[tot] = v; }   int main() {     read(n);     for (int i = (1); i <= (n); ++i) read(a[i]), f[i][i] = a[i];     for (int k = 2; k <= n; ++k)       for (int i = 1; i + k - 1 <= n; ++i)         for (int j = i; j < i + k - 1; ++j)           if (f[i][j] && f[i][j] == f[j + 1][i + k - 1]) {             f[i][i + k - 1] = f[i][j] + 1;             break;           }     for (int i = 1; i <= n; ++i)       for (int j = i; j <= n; ++j)         if (f[i][j]) add(i, j + 1);     memset(v, 0x3f, sizeof(v));     v[1] = 0, q.push(1);     int x, y;     while (q.size()) {       x = q.front(), q.pop(), in[x] = 0;       for (int i = head[x]; i; i = nxt[i]) {         if (v[y = ver[i]] > v[x] + 1) {           v[y] = v[x] + 1;           if (!in[y]) q.push(y), in[y] = 1;         }       }     }     printf( %d n , v[n + 1]);     return 0;   }   