func_code_string: #include <bits/stdc++.h>   #pragma comment(linker,  /STACK:136777216 )   using namespace std;   int bits(int x) { return x == 0 ? 0 : 1 + bits(x & (x - 1)); }   int v[30][30];   int dp[2][26][111];   int main() {     const int ninf = -1000000;     for (int(i) = 0; (i) < (30); (i)++)       for (int(j) = 0; (j) < (30); (j)++) v[i][j] = 0;     string s;     int K, m;     cin >> s >> K >> m;     int n = (int)(s).size();     K = min(K, n);     char a, b;     int c;     for (int(i) = 0; (i) < (m); (i)++) {       cin >> a >> b >> c;       v[a -  a ][b -  a ] = c;     }     for (int(j) = 0; (j) < (26); (j)++)       for (int(k) = 0; (k) < (K + 1); (k)++) dp[0][j][k] = ninf;     for (int(j) = 0; (j) < (26); (j)++)       if (j == s[0] -  a )         dp[0][j][0] = 0;       else         dp[0][j][1] = 0;     int add;     for (int i = 1; i < n; i++) {       int now = i % 2, bef = 1 - now;       for (int(j) = 0; (j) < (26); (j)++)         for (int(k) = 0; (k) < (K + 1); (k)++) dp[now][j][k] = ninf;       for (int(prev) = 0; (prev) < (26); (prev)++)         for (int(cur) = 0; (cur) < (26); (cur)++) {           if (cur == s[i] -  a )             add = 0;           else             add = 1;           if (add == 0)             dp[now][cur][0] =                 max(dp[now][cur][0], dp[bef][prev][0] + v[prev][cur]);           for (int(ch) = (1); (ch) < (K + 1); (ch)++) {             dp[now][cur][ch] =                 max(dp[now][cur][ch], dp[bef][prev][ch - add] + v[prev][cur]);           }         }     }     int r = ninf, t = (n - 1) % 2;     for (int(j) = 0; (j) < (26); (j)++)       for (int(k) = 0; (k) < (K + 1); (k)++) r = max(r, dp[t][j][k]);     cout << r;     return 0;   }   