DP bottom up
\n# Code\n\nclass Solution {\n    public int palindromePartition(String s, int k) {\n        char[] chars = s.toCharArray();\n        int n = chars.length;\n   
\n# Code\n```\nclass Solution {\n    public int palindromePartition(String s, int k) {\n        char[] chars = s.toCharArray();\n        int n = chars.length;\n        int[][] dp = new int[n][n];\n        int[] cache = new int[n+1];\n        for (int i = n - 1; i >= 0; i--) {\n            char a = chars[i];\n            for (int j = i+1; j < n; j++) {\n                char b = chars[j];\n                if (a != b) {\n                    if (j == (i + 1)) dp[i][j] = 1;\n                    else dp[i][j] = dp[i+1][j-1] + 1;\n                } else {\n                    dp[i][j] = dp[i + 1][j - 1];\n                }\n            }\n            cache[i] = dp[i][n-1];\n        }\n        for (int i = 1; i < k; i++) {\n            int upperBound = n - 1 - i;\n            int[] currentCache = new int[n];\n            for (int j = upperBound; j >= 0; j--) {\n                int currentMin = Integer.MAX_VALUE;\n                for (int l = j; l <= upperBound; l++) {\n                    currentMin = Math.min(currentMin, dp[j][l] + cache[l+1]);\n                }\n                currentCache[j] = currentMin;\n            }\n            cache = currentCache;\n        }\n        return cache[0];\n    }\n\n}\n```
['Java']