There is not much to talk about AC automatic machines. It is better for others to read their papers. This is the truth.
Below is:
Original Aho-Korasick automatic paper
Papers recommended by notonlysuccess blog
An AC automatic machine is used to construct a pattern matching machine.
A pattern matching machine has a series of States, each of which is represented by a positive integer.
The pattern matching machine also has the status transition function and an output function.
When a character x is used, the pattern matching machine processes the character. If the character is in a certain state, it matches the next character. If the character is not used, the State is transferred.
The above is the general meaning of the AC automatic machine.
But we still need to solve two problems:
Goto function related to the status
Failure function related to status transfer
The construction of the goto function directly uses the dictionary tree, and the failure function uses the idea of the kmp algorithm.
Pay attention to the following points:
1) Use a val array to mark whether the node is the end of a keyword. Of course, in practice, val can also record the number of occurrences of the mode, in addition, the keyword first appears in the front position of val.
2) in a dictionary tree, a leaf node may end with multiple keywords at the same time. Therefore, you can open a last array record or write a while loop to export data.
3) The optimization in some details is not particularly understandable, although it does not affect efficiency. But you still need to think about it yourself.
4) connecting all nodes with edges is a directed graph, which can be processed using a matrix or DP.
The following are the questions about AC automatic machines.
Template question:
Hdu 2222 Keywords Search
Hdu 2896 virus attack
Hdu 3065 virus attack continues
AC + DP:
Poj 3691 DNA repair
Create a directed graph and then perform DP on the graph.
When matching starts, it must start from the status 0, and then you can constantly modify the characters. Use d (I, j) to indicate that when the mother string matches the I character, number of characters to be modified in status j. Then we can obtain the following recursive relationship: d (I + 1, next (j) = d (I, j) + (idc (j) = T [I])? 0: 1
Questions about the AC + matrix:
Poj 2778 DNA Sequence
First, create a directed graph, convert the directed graph into a matrix, and obtain the answer through the Rapid power of the matrix.
Matrix [I] [j] indicates the number of paths from I to j, and then evaluates the matrix ^ n power, you can get the number of paths from I to j in n steps, that is, the number of strings with n length.
There are a lot of questions, and some are also very difficult to keep updating ......