func_code_string: #include <bits/stdc++.h>   using namespace std;   char str[1010];   int pri[510][510];   int pre[510][510];   int f[510][510];   bool v[510] = {0};   int N;   void init() {     gets(str);     scanf( %d , &N);   }   void prework() {     int len = strlen(str);     for (int i = 0; i < len; ++i)       for (int j = 0; j < len; ++j) {         int p = 0;         int tmp = 0;         while (i + p < j - p) {           if (str[i + p] != str[j - p]) tmp++;           p++;         }         pri[i + 1][j + 1] = tmp;       }   }   void dp() {     int len = strlen(str);     memset(f, 10, sizeof(f));     f[0][0] = 0;     for (int i = 1; i <= len; ++i) {       for (int j = 1; j <= N; ++j)         for (int k = 0; k < i; ++k) {           if (f[i][j] > f[k][j - 1] + pri[k + 1][i]) {             f[i][j] = f[k][j - 1] + pri[k + 1][i];             pre[i][j] = k;           }         }     }     int Ans = 1000000000;     int p;     for (int i = 1; i <= N; ++i)       if (f[len][i] < Ans) {         Ans = f[len][i];         p = i;       }     printf( %d n , Ans);     int q = len;     while (q != 0) {       v[pre[q][p]] = 1;       int x = 0;       while (pre[q][p] + x < q - 1 - x) {         str[pre[q][p] + x] = str[q - 1 - x];         x++;       }       q = pre[q][p];       p--;     }     v[0] = 0;     for (int i = 0; i < len; ++i) {       if (v[i]) putchar( + );       putchar(str[i]);     }   }   int main() {     init();     prework();     dp();     return 0;   }   