func_code_string: #include <bits/stdc++.h>   using namespace std;   int N, M, M2, B;   const int MAXN = 100015;   const int MAXM = 20;   const int MAXM2 = (1 << 20);   char S[MAXN];   int bitc[MAXM2];   int bitl[MAXM2];   int dp[MAXM2];   int cnt[MAXM][MAXM];   int mcnt[MAXM2][MAXM];   int last;   int main() {     cin >> N >> M >> S;     M2 = (1 << M);     B = M2 - 1;     for (int i = 0; i < M; ++i)       for (int j = 0; j < M; ++j) cnt[i][j] = 0;     bitc[0] = 0;     bitl[0] = 0;     dp[0] = 0;     for (int j = 0; j < M; ++j) mcnt[0][j] = 0;     for (int i = 1; i < M2; ++i) {       int b = i & (i - 1);       bitc[i] = bitc[b] + 1;       for (int j = 0; j < M; ++j)         if ((1 << j) & i) {           bitl[i] = j;           break;         }       for (int j = 0; j < M; ++j) mcnt[i][j] = 0;       dp[i] = 1e9;     }     for (int i = 0; i < N - 1; ++i) {       if (S[i] == S[i + 1]) continue;       ++cnt[S[i] -  a ][S[i + 1] -  a ];       ++cnt[S[i + 1] -  a ][S[i] -  a ];     }     for (int i = 1; i < M2; ++i)       for (int j = 0; j < M; ++j)         mcnt[i][j] = mcnt[i & (i - 1)][j] + cnt[bitl[i]][j];     for (int i = 0; i < M2; ++i)       for (int j = 0; j < M; ++j) {         if (((1 << j) & i) == 0)           dp[i | (1 << j)] = min(dp[i | (1 << j)],                                  dp[i] + bitc[i] * (mcnt[i][j] - mcnt[B ^ i][j]));       }     cout << dp[B] << endl;     return 0;   }   