[Explanations] magic ring

Topic Link

Title effect: you \ (m \) black balls, \ (nm \) white balls, requires them strung together a ring (rotated isomorphic same operator, not necessarily the same isomorphic flip), the ring so that no contiguous stretch of black ball, which is longer than \ (K \) . Find a few programs.

Not at allSpecific solution:

Ring from a first cut point can be observed sequence of cycles may occur. The cycle setting section length \ (P \) , it certainly has \ (P | \ GCD (m, n-) \) .

Sequence length is set \ (K \) , it may be made of \ (DP \) length was calculated \ (K \) , the first valid sequence number for the white ball. Provided by the \ (I \) white balls, \ (J \) black balls, with the first one of the legitimate sequence number of white balls as \ (F_ {I, J} \) , consider two adjacent white ball interval \ (D \) , there \ (F_ {I, J} = \ sum_ {D} = 0 {^ mf_-I. 1, JD} \) , can quickly optimize power polynomial.

however,ClearThis will repeat count. Consider a \ (I \) white balls, \ (J \) black balls, the minimum cycle knots \ (i + j \) to the number of sequences of white balls start to \ (s_ {i, j} \ ) , then \ (S_ {I, J} = F_ {I, J} - \ sum_ {T | I, T | S _ {J} \ FRAC IT, \ JT FRAC} \) . May \ (\ FORALL D | n-\ & \ & D | J \) , obtains \ (F _ {\ FRAC {nm} D, \ FRAC MD} \) , then violence enumerated factor determined \ (s _ {\ {D} nm FRAC, \ FRAC MD} \) .

It may then be determined from \ (I \) white balls, \ (J \) black balls, the minimum cycle knots \ (i + j \) different from the nature of atoms in a ring, i.e., \ (\ frac {s_ { I, J}} I \) , the cumulative answer.

Probably \ (O (n \ log ^ 2n) \) or \ (O (the n-\ the n-log) \) ? Anyway, it is too loose.

It is said that \ (O (n \ log \ log n) \) approach?

Code ugly not posted ......

Guess you like

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