[POI2010] CHO-Hamsters


Given \ (n-\) string ( \ (n-\ Leq 200 is \) ), \ (\ SUM | S | \ Leq. 5 ^ 10 \) . So that they Solitaire, in which the same part of the end to end would cover the two words. Q comprises \ (m \) minimum length of long strings (repeat, are not used) of. ( \ (M \ ^ Leq 10. 9 \) )


Problem-solving ideas

This question is essentially the model can be transformed into a graph theory. We can imagine a point each string, the cost of one point to another point is that the increase in the number Jieshangqu length. This graph is directed with a ring (also from the ring). To give the desired title \ (m \) strings minimum long length, becomes just a through \ (m \) shortest path points (start point to count the original length).

Thus there are two problems: one is how fast the pretreatment right side, the second is how to quickly determine the shortest path length.

The first question, open O2 violence before. Correct answer is required AC automaton.

The second problem is a classic problem - through the FIG \ (K \) shortest path sides, the solution is quick power optimization Floyd matrix. Elaborate:

For a picture, a first adjacency matrix. An adjacency matrix \ (g_ {i, j} \) can be understood as the point \ (I \) point \ (J \) just after a shortest side. Now if the required point \ (I \) point \ (J \) just after the shortest of the two sides should be done \ (g '_ {i, j} = \ min \ {g_ {i, k} + {K G_, J} \} \) . \ (g '\) is right across the two sides, and want to know if the three sides so \ (g' '_ {i , j} = \ min \ {g' _ {i, k} + g_ {k , J} \} \) . And so we have \ (G ^ m_Low {I, J} = \ min \ {^ {m-G. 1} _ {I, K} {K + G_, J} \} \) . This is a variant of matrix multiplication, but fortunately it still is associative. Therefore, we directly \ (g \) do matrix quick power on it.

It is worth mentioning that in the standard matrix rapid power, we \ (ans \) is initialized to the identity matrix. And now we have changed the definition of matrix multiplication, matrix structure means should also make certain changes:
\ [\ bmatrix the begin {0} & \ infty & \ cdots & \ infty \\ \ infty & 0 & \ cdots & \ infty \\ \ vdots & \ vdots & \ ddots & \ vdots \\ \ infty & \ infty & \ cdots & 0 \ end {bmatrix} \] i.e. the diagonal is 0, the rest are \ (\ infty \ ) .

Guess you like

Origin www.cnblogs.com/qixingzhi/p/11233027.html