Hdu2481 toy)

Source: Internet
Author: User

This is really a good question!

(Http://blog.csdn.net/jayye1994/article/details/37814965) bzoj 1002: [fjoi2007] Rotavirus

The previous question is the same after rotation, which is considered the same situation. Just a small difference,

DP was used in the previous question, which used DP, sieve prime number, binary simulated multiplication, matrix, fast power, Euler's function, and Burnside theorem ..

It is also a person (question ).. How is the gap between people and questions so big ..

Data range: There are N points around, and the answer is modulo m, n <= 10 ^ 9, m <= 10 ^ 9


Ideas:

To answer this question, we must first talk about the Burnside theorem. If we don't, we can do a few things. Liu lujia's Training Guide provides some help.

Then there are n replicas, which are inmotion and I units (I <n ).

First of all, solving the problem is actually the result of rotavirus requirements. But here n <= 10 ^ 9, the complexity of my calculation is O (n ^ 2,

The calculation formula cannot be a quick power, then the question of the DP formula can be introduced DP [I] [1] = 3 * DP [I-1] [1]-DP [I-2] [1], if I push the results to ans, I will be dizzy,

Then you can create a table to find the rule .. Ans [I] = 3 * ans [I-1]-ans [I-2] + 2, so the immobile situation is solved...

The next step is the rotation requirement. After rotating I units, it is easy to know that the cycle is N/gcd (n, I), and the number of cycles is gcd (I, n ), therefore, each gcd (I, n) is composed of identical parts, as shown in


After thinking about it, I posted the DP of the previous question. It looks clear.

The question is to find the minimum number of spanning trees. The center point must be connected to a circle of points around it. You can ignore the ring and consider the chain first.

DP [I] [0] indicates that point I has not been connected to the center, and that the front I-1 point and the center point or point I are connected

DP [I] [1] indicates that all the first I points have been connected to the center point.

It is easy to introduce the state transition equation:

DP [I] [0] = DP [I-1] [0] + dp [I-1] [1]

DP [I] [1] = DP [I-1] [0] + dp [I-1] [1] * 2

For N rotavirus, We can enumerate the number of points connected to the first point and the number of surrounding points. The remaining points are a chain.


For example, if I = 2, n = 6, then gcd () = 2 and the cycle length is 2, that is, the red and green lines are repeated, then we can know that all vertices in the center are connected. If the vertices on both sides are connected to the center, the Green Line Segment will be deleted. The number of vertices is DP [gcd (I, n)]. [1]. The Euler's function can be used to calculate the number of loops whose length is D. Therefore, I (I <= N) is not required to be enumerated, but the factor of N is needed.

If a point on one side is not connected to a central point, a green line is required. The number is 2 * DP [gcd (I, n)] [0]. because there are two sides, so take 2, but note that if all the points in this section are not connected to the center, it will not work, so the number of cases must be reduced by 2*1.

Then the problem has almost been solved, but there is another problem. The final answer still needs to be divided by N, but N and m are not necessarily mutually qualitative, so we cannot find the reverse element.

So evaluate (a/B) mod C, because we know that a/B is an integer, ANS = A/B + XC, then ans * B = a + xbc = A Mod (BC), so we can find a mod (BC) and divide it by B. The middle multiplication will lead to long, therefore, we need to add binary bits to simulate multiplication.


Code:


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.