Atcoder Regular Contest 060 F answer the question first asked to prove

All started

So that \ (x \) is a string, \ (the p-\) is a positive integer. If for meeting \ (0 \ le i <| x | -p \) any integer \ (I \) satisfies \ (X [I] = X [I + P] \) , then \ (P \) referred to \ (x \) cycle. \ (X \) is the minimum period is denoted as \ (per (X) \) . For example, \ (per (abcabcabcab) =. 3 \) .

Order \ (N \) is the input string \ (W \) length. Case divided as follows:

(A) If \ (W \) is a good string (e.g. \ (W = Ababa \) )
(B) when \ (per (w) = 1 \) (for example, \ (W = AAAAA \) )
(c) other cases (e.g. \ (W = ABCABCABC \) )

In the case of (a), is significantly optimal expression \ (1 \) , for optimal expression \ (1 \) .
In the case of (b), for the optimal expression \ (N \) , for optimal expression \ (1 \) .
In the case of (c), we can prove best expressed as \ (2 \) (see the following theorem \ (5 \) ).

Theorem 2

By the \ (\ text {KMP} \ ) or \ (\ text {Z-Algorithm } \) can be seen, if a positive integer \ (p, q \) is the string \ (X \) period, and \ (p + q- \ gcd (the p-, q) \ Le | the X-| \) , then \ (gcd (p, q) \) is \ (x \) cycle.

Lemma 3

Order \ (X \) non-empty string, the following two are equivalent.

(I) \ (X \) is not a good string

(II) \ (| X | / per (X) \) of \ (2 \) or a larger integer.

First, if (ii) holds, then (i) definitely established, so in the following (i) is (ii).

If \ (x \) is not a good string, \ (| the X-| / per (the X-) \ GE 2 \) is obvious from the definition. Next we just need to prove that \ (| x | / per ( x) \) is an integer, \ (the X-\) is not a good string implies the existence of a string \ (y \) and an integer \ (k \ GE 2 \) , so \ (X \) is the \ (Y \) repeating \ (K \) string views obtained. Order \ (P = per (X), Q = | Y | \) , then \ (P \ Le Q = | X | / K \ Le | X | / 2 \) , since \ (p, q \) are is \ (X \) cycle, and satisfies \ (P + Q- \ GCD (P, Q) \ Le | X | \) , from Theorem \ (2 \) known, \ (\ GCD (P, Q) \) is \ (X \) period, assuming \ (| x | / per ( x) \) is not an integer, the \ (Q \) instead of\ (P \) multiples of this time \ (\ GCD (P, Q) <P \) , which \ (p = per (x) \) is \ (X \) is contrary to the minimum period, so \ ( | x | / per (x) \) is an integer.

Lemma 4

Order \ (X \) is the length \ (2 \) or more strings. So \ (m = | the X-| \) . Furthermore, let \ (Y = X [m. 1 ... -. 1] \) . If \ (X \) is not a good string, and \ (per (X) \ =. 1 Not \) , then \ (Y \) is a good string.

Suppose \ (Y \) is not a good string. Order \ (P = per (X), per Q = (Y) \) . Lemma \ (3 \) and the previous assumptions, \ (P \) is the (m \) \ divisors, \ (Q \) is \ (| y | = m- 1 \) submultiple. Since \ (m \) and \ (m-1 \) coprime, so \ (P \) and \ (Q \) are also relatively prime, i.e., \ (\ GCD (P, Q) =. 1 \) , in addition, \ (P \ Le m / 2, Q \ Le (m-. 1) / 2 \) , where \ (P \) is \ (Y \) period, and therefore, according to Theorem \ (2 \) , \ (\ gcd (p, q) = 1 \) a \ (Y \) of the cycle, so the \ (x [0] = x [p] \) starts, \ (X \) is the last \ (m-1 \)Becomes all the characters \ (x [0] \) same character, then \ (per (X) =. 1 \) , which conflicts with the premise, it \ (Y \) is a good string.

Theorem 5

For a string \ (W \) , assuming \ (W \) is not a good string, and \ (per (W) \. 1 = Not \) . In this case, \ (W \) is best expressed as \ (2 \) .

Length \ (1 \) string is clearly a good string. Further, according to Lemma \ (. 4 \) , \ (W [. 1 ... | W | -1] \) is a well string, so the sequence \ ((w [0], w [1 ... | w | -1]) \) is \ (w \) is one of the best expression. Obviously, \ (w \) is no more or less optimal expression 1. The \ (W \) optimal expression 2.

Guess you like

Origin www.cnblogs.com/mleautomaton/p/11609512.html