标签:put || exp 过程 NPU color ati art ali
1 public int minCut(String s) { 2 int slen = s.length(); 3 int[][]pa = new int[slen][slen]; 4 int[]dp = new int[slen]; 5 for(int i = 0;i<slen;i++) 6 dp[i] = i; 7 for(int i = 0;i<slen;i++) 8 Arrays.fill(pa[i],0); 9 for(int i = 1;i<slen;i++) { 10 for(int j = 0;j<=i;j++) { 11 if(s.charAt(j)==s.charAt(i)&&((i-j<2)||pa[j+1][i-1]==1)) { 12 pa[j][i] = 1; 13 if(j!=0)dp[i] = Math.min(dp[i],dp[j-1]+1); 14 else dp[i] = 0; 15 } 16 } 17 } 18 return dp[slen-1]; 19 }
动态规划——Palindrome Partitioning II
标签:put || exp 过程 NPU color ati art ali
原文地址:https://www.cnblogs.com/messi2017/p/9904220.html