[Explanations] palindrome string yww and trees

Topic Link

Intended to repeat the question: to a tree, each side has a character ( \ (0 \) or \ (1 \) ), how much demand there is for \ ((the X-, the y-) (the X-<the y-) \) , meet \ (X \) to \ (Y \) character string on the side of the path consisting of palindromic sequence string.

And an immortal question ah

Other methods can not easily find the answer, consider dotted.

After a point of palindrome string only two situations:

  • The point of this string is divided into two sub-strings of equal length, and two symmetric sub-strings.
  • This string is divided into two unequal length at this point (possibly \ (0 \) ) substring, and a long string of splicing a short string and string together palindrome.

First find out the string to the center of gravity for the opening of all paths indicated, consider the first case: You can build a dictionary tree, look for the path of each string represents the number of different endpoints can be calculated and represent the same string the number of paths.

Consider again the second case: i.e. half the length of the short string matching strings. Since a plurality of strings to be matched, AC automaton can be established, depending on the endpoint definition shorter strings are long strings in the tree fail ancestor.

according tobroder理论

A palindromic sequence palindromic all prefixes may be represented as \ (O (\ log n) \) th arithmetic sequence

All arithmetic sequence can be recorded is long palindromic prefix string Trie tree formed, and then the DFS tree fail, with the number of ancestors of the current array access node of each length string records, according to the arithmetic sequence count routine, with \ (\ sqrt {n} \ ) length of \ (\ sqrt {n} \ ) of the array to record the tolerance \ (\ leqslant \ sqrt {n } \) case, while recording all length, can be done \ (O (\ sqrt {n }) \) to modify the query.

Seeking palindrome prefix may have Trie tree his father transferred from the state and sentenced to a string is palindrome string can use the string hashes.The number of films is not selected, two lines of tears burst 0

Code ugly not posted ......

Guess you like

Origin www.cnblogs.com/ztc03/p/12026091.html