-1 blind BB
Me: hey Query teach me the smallest palindrome decomposition, OK?
LQY: I will not ah.
I: So you that \ (O (nlogn) \) the solution come from?
LQY: that is optimized dp.
Facts have proved that the smallest palindrome decomposition,LQYtxdy So this blog will be handling some of the LQY ppt
0. Definitions.
Minimum palindrome decomposition: As the name suggests, is to \ (S \) decomposed into segments as little as possible, so that each segment is a palindromic sequence.
\ (border \) : There is a string \ (s \) , we both \ (s \) prefix is \ (s \) suffix string called \ (s \) is \ (border \) .
Stage: set the string \ (the X-UY = \) , where \ (x, y \) are palindromic sequence and the \ (y \) is \ (x \) when the true suffix, we \ (| u | = | x | - | y | \) called \ (x \) is a stage. In particular, if \ (y \) is \ (x \) is the longest palindrome true suffix, then \ (| u | \) to \ (x \) is the smallest stage.
1. Lemma
Lemma 1: Suppose \ (Y \) is the palindromic sequence \ (X \) one \ (border \) , then \ (Y \) is a palindromic sequence.
Lemma 2: Suppose \ (Y \) is the \ (X \) a \ (border \) , and \ (| X | \ Leq 2 | Y | \) , then \ (X \) is a palindromic sequence when and only if \ (Y \) is a palindromic sequence.
Both Lemma came obvious.
Lemma 3: Suppose \ (X \) is a palindromic sequence, \ (Y \) is the \ (X \) is the longest suffix is palindromic, \ (Z \) is \ (Y \) is the longest palindromic true suffix set \ (X = UY, \; Y = VX \) , there
- Lemma 3-1: \ (| U | \ geq | v | \)
Lemma 3-2: If \ (| U | = | v | \) , then \ (u = v \)
Lemma 3-3: If \ (| U |> | v | \) , then \ (| u |> | z | \)
prove:
Obviously \ (y \) is \ (x \) is the longest palindrome \ (border \)
So disposed string \ (U ', V' \) , satisfies \ (x = uy = yu ' , y = vz = zv' \)
Proof 3-1
Suppose \ (| U | <| V | \) , FIG known, there are \ (| U | \) of \ (Y \) is the minimum phase, and \ (| V | \) of \ (Y \) minimum stage contradiction.
Proof 3-2
3-1 is known from FIG proof, \ (V \) of \ (U \) prefix Obviously when \ (| v | | u | = \) when, \ (U = V \) .
Proof 3-3
First \ (| u | \ geq | \ | y) obviously is proved time.
Suppose \ (| U | <| Y |, | U |> | V | \) , and \ (| U | \ Leq | Z | \) . Strings disposed \ (U ', V' \) , satisfies \ (X = UY = Yu ', Y = VZ = ZV' \) .
Since \ (| U | \ Leq | Z | \) , so \ (2 | Z | \ GEQ | UZ | \) , obtained according to Lemma 2, \ (UZ \) is a palindromic sequence. There \ (| U |> | v | \) , so \ (| v | \) is \ (| x | \) minimum phase, and \ (| u | \) is \ (| x | \) the minimum palindrome decomposition contradiction.
So good on all pre-lemma proved over ~
2. Minimum palindrome decomposition
Finally get to the point yet
Common decomposition approach is seeking a palindrome \ (O (n ^ 2) \) a \ (\ texttt DP} {\) : set \ (dp [i] \) represented by \ (I \) , the end character the minimum string palindrome decomposition, there are \ (DP [I] = {J min_ <I, J \ in P_i} \ {DP [J] + 1'd \} \) , where \ (P_i \) stored satisfy \ (s [j + 1 ... i] \) is the palindromic sequence \ (J \) .
The \ (P_i \) in the elements from small to large, the difference a bit, then write \ (P_i \) differential array is \ (Q_i \) , will find a property:
\ (Q_i \) in different values at most \ (log_i \) a
Lemma 3-3 understood, if \ (| U |> | V | \) , there are \ (| X |> | U | + | Z |> 2 | Z | \) , i.e. \ (| Z | \ Leq \ FRAC {| the X-|} {2} \) , a maximum of iterations \ (log_i \) times.
There is also a nature:
Note triplet \ ((i, delt, sz ) \) represents \ (Q_i \) have \ (sz \; (sz \ geq 2) \) differential value \ (the DELT \) , if there is a \ ((I, the DELT, SZ) \) , must exist \ ((i-delt, delt , sz-1). \)
In fact, quite obvious?
Then consider how to optimize the \ (\ texttt {dp} \) :
Use \ (Q_i \) in different values only \ (log_i \) a, we can follow (Q_i \) \ respectively shift in values.
The establishment of an auxiliary array \ (G [i] [DELT] \; (DELT \ in Q_i) \) , expressed tolerance \ (delt \) contribution palindrome suffix of the answer.
There $ g [i] [delt] = min (g [i-delt] [delt], dp [mx_ {delt} -1] +1) $ // not understood, ask first LQY
Violence then sweep \ (g [i] [delt ] \) Update \ (DP [I] \) .
Then \ (g [i] [delt ] \) can actually be scrolled in \ (i-delt \) position memory \ (g [i] [delt ] \) on the line.
Thus, space can be \ (O (n-) \) , time \ (O (nlogn) \) complexity for the Minimum palindromic decomposed.
3. The minimum palindromic exploded + PAM
Gugu Gu