c++ dp solution
\nclass Solution {\npublic:\n    int palindromePartition(string s, int k) {\n        int len = s.size();\n        vector<vector<int>> palindrome (len, vector <i
```\nclass Solution {\npublic:\n    int palindromePartition(string s, int k) {\n        int len = s.size();\n        vector<vector<int>> palindrome (len, vector <int> (len, 0));\n        for (int i=0;i<len;i++)\n        {\n            for (auto d: {0,1})\n            {\n                int c = 0;\n                int j=i-1,k=i+d;\n                while(j>=0&&k<len)\n                    palindrome[j--][k++] = s[j]!=s[k]?++c:c;\n            }\n        }\n        vector<int> dp(len,0);\n        for (int i=0; i<len; i++)\n            dp[i] = palindrome[i][len-1];\n        int nk = 1;\n        while(nk < k)\n        {\n            for (int i=0; i<len; i++)\n            {\n                dp[i] = len;\n                for (int j=i;j<len-nk;j++)\n                    dp[i] = min(dp[i],palindrome[i][j] + dp[j+1]);\n            }\n            nk++;\n        }      \n        return dp[0]; \n    }\n};\n```\n
[]