I recently started to read abour dynamic programming, and I am doing an exercise on it. The problem to solve: Given a String, find the least amount of palindromes it can be split into, and print out the solution. I found this article on here: Is there an algorithm for checking if a string is a catenation of palindromes?
It helps me, but I dont quite get the last step of the answer: Quote:
Now, you can compute
s[1,…,j+1]
, by checking for each $1\le i\le j−1$ whethers[1,…,i]
can be decomposed, and ifs[i+1,…,j+1]
is a palindrome (using the above 2D table). Giving a $\Theta(n^2)$ time and $\Theta(n^2)$ space algorithm.
What do I do here? I am confused.
btw, that question deals with "whether a string is a concatenation of non-trivial palindromes", while you want a decomposition into the minimum numbers, possibly including the trivial decomposition (each character is a palindrome in itself).
The dynamic programming algorithm in that answer can be modified to maintain the actual number of palindromes in the minimal decomposition of $s[1 \dots j]$ (instead of a boolean Yes/No as in that answer).
– Aryabhata Jul 18 '14 at 07:01