4
/// Count Number of changes to be done5
/// to make substring of s from i to j7
int changes(int i, int j, string &s) {10
cnt += (s[i++] != s[j--]);15
int recur(int idx, int k, string &s) {16
/// If Reached end of s and found partions to be done 017
/// return 0 , otherwise return INT_MAX/any big number18
if (idx == s.size()) {19
return (k == 0) ? 0 : 1e7;22
/// Partitions to be done have completed , but23
/// we are not at the end of the string24
/// return INT_MAX/any big number29
if (dp[idx][k] != -1) {33
/// Partitioning the String35
for (int i = idx; i < s.size(); i++) {36
ans = min(ans, changes(idx, i, s) + recur(i + 1, k - 1, s));38
return dp[idx][k] = ans;41
int palindromePartition(string s, int k) {46
memset(dp, -1, sizeof(dp));47
return recur(0, k, s);