c++ dp O(kn^2)
\nclass Solution {\npublic:\nint palindromePartition(string s, int k) {\n// number of moves to make s[i..j] to 1 palindrome\n    int dp1[101][101];\n    memset(
```\nclass Solution {\npublic:\nint palindromePartition(string s, int k) {\n// number of moves to make s[i..j] to 1 palindrome\n    int dp1[101][101];\n    memset(dp1, 0, sizeof(dp1));\n// number of moves to make s[i..end] to K palindromes\n    int dp2[101][101];\n    memset(dp2, 0, sizeof(dp2));\n    \n    for (int l = 2; l <= s.size(); l++) {\n        for (int i = 0; i + l <= s.size(); i++) {\n            int j = i + l - 1;\n            if (s[i] == s[j])\n                dp1[i][j] = i+1 <= j-1 ? dp1[i+1][j-1] : 0;\n            else\n                dp1[i][j] = (i+1 <= j-1 ? dp1[i+1][j-1] : 0) + 1;\n            if (j == s.size() - 1)\n                dp2[i][1] = dp1[i][j];\n        }\n    }\n    for (int K = 2; K <= k; K++) {\n        for (int i = 0; i + K <= s.size(); i++) {\n            dp2[i][K] = INT_MAX;\n            for (int m = i; m + K <= s.size() ; m++) {\n// number of moves to make s[i..end] to K palindromes = \n// min (number of moves to make s[i..m] to 1 palindromes  + number of moves to make s[m+1..end] to K-1 palindromes)\n// for m in [i..end-1]\n// beacasue s[i] must belong to one palindrome\n                dp2[i][K] = min(dp2[i][K], dp1[i][m] + dp2[m+1][K-1]);\n            }\n        }\n    }\n    return dp2[0][k];\n}\n};\n```
[]