bzoj3926: [Zjoi2015] The gods of Gensokyo some understandings of generalized suffix automata

Source: Internet
Author: User

First of all, the understanding of the suffix automata is mainly the understanding of the construction process.

Construct, we have got the suffix automaton of the front L character, now we want to get l+1 character suffix automaton, what need to change?

First, the substring $[0,l+1) $ corresponds to a state that does not exist and should establish a state to represent the string, obviously, the right set of this state (NP) is {l+1},max=l+1.

Now that a new state has been established, we have two things to do: to find the state that can be transferred to this state, to establish a link, to determine the min of the state, to find its father on the parent tree.

The state that can be transferred to $np$ is obviously the right set containing the state of L, which is the state of P (substring $[0,l) $, and the ancestor of P.

Set C = s[l+1] As we climb up the P, we will encounter some non-$c$ transitions, and it is clear that the transfer of C will be connected directly to it.

If all does not have $c$ transfer, then NP father is set to root, then found NP min, that is, 1.

Otherwise, we are now in the first state with a transfer of C, where p represents the state of the red part.

For example, there are at least two red sections, they are the same, and one position is L, the next character in the other position is C, (note that the red line and the right end of the blue segment represent its position, and the left side represents the position minus the $max$ place). Set Q=p->to[c], at this time we can determine NP min, is p->max+2, that is, NP father Max should be p->max+1.

So, if it is the green state in the picture, that is Q->max = = P->max+1 We can announce that we have found the father of P. Then make p->par = Q, so that the position of l+1 is inserted in the right set of Q and all ancestors.

If it is a blue state, we have to consider creating a new node NQ make it max for p->max+1, to be the father of NP, so we make, Nq->max = P->max + 1, Np->par = NQ, The two previously mentioned problems have all been solved, but in fact we need to insert l+1 in the right set of the p->to[c] state, so we make Nq->par = Q->par, Q->par = NQ, Then NQ this state indicates that the right set is exactly what the p->to[c] needs, and then we convert all the ancestors of P and all p to Q, which also requires NQ and q to have the same transfer, need memcpy (Nq->to, Q->to, sizeof (nq->to));

bzoj3926: [Zjoi2015] The gods of Gensokyo some understandings of generalized suffix automata

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.