[JAVA] Clean DP Solution
\nclass Solution {\n    public int palindromePartition(String s, int K) {\n        int n = s.length();\n        int[][] cost = new int[n][n];\n        for(int i
```\nclass Solution {\n    public int palindromePartition(String s, int K) {\n        int n = s.length();\n        int[][] cost = new int[n][n];\n        for(int i=0;i<n;i++)\n            for(int j=i; j<n;j++)\n                cost[i][j] = minChanges(s, i, j);\n        \n        int[][] dp = new int[n][K+1];\n        for(int[] row: dp){\n            Arrays.fill(row, Integer.MAX_VALUE/2);//May overflow using MAX_VALUE;\n        }\n        \n        for(int i=0;i<n;i++){\n            for(int k=1;k<=K;k++){\n                dp[i][1] = cost[0][i];\n                for(int j=0;j<i;j++){\n                    dp[i][k] = Math.min(dp[i][k], dp[j][k-1] + cost[j+1][i]);\n                }\n            }\n        }\n        return dp[n-1][K];\n    }\n    \n    int minChanges(String s, int i, int j){\n        int c = 0;\n        while(i<j){\n            if(s.charAt(i++)!=s.charAt(j--)) c++;\n        }\n        return c;\n    }\n}\n```
[]