Nine Chapters count judges Net-original websitehttp://www.jiuzhang.com/problem/48/
Topics
For a given string, the minimum number of partitions is required to divide the string into substrings, each of which is a palindrome string. such as Abaab, requires at least 1 division, the string is divided into: A|baab, each part is a palindrome string.
Answer
This is a typical dynamic programming problem of partitioning on a string. The general state representation is as follows: F[i] means dividing the substring of the first I character into a minimum number of strings, each string being a palindrome. Then there is the state transfer equation: f[i] = MIN (F[j] + 1, j<i && j+1~i is a palindrome string). Here to determine whether a string is a palindrome string, you can use O (n) judgment, the overall complexity of I * j * To determine the palindrome string = O (n^3). However, this complexity can be further optimized. That is, there is no need to re-determine whether a string is a palindrome every time. Can be a little more space, such as using ispalindrome[i][j] to represent I to J is a palindrome string. It is clear that this array is recursive and can be resolved in O (n^2) time. So the overall time complexity can be reduced to O (n^2)
Reference Program:
http://answer.ninechapter.com/solutions/palindrome-partitioning-ii/
Nine-chapter algorithm surface test 48 split Palindrome string