Question 1:
Question:
There are n pieces of sugar, two people take turns to take, each time can only take the prime number, can not take the loss. If the winner wins, the minimum number of wins is required. (N <= 10000)
Problem solving process:
1. See that the range of N is relatively small. first create a prime number table and then DP.
2. f [I] indicates I sugar. If the first person wins, the minimum number of victory steps are required. If the first person wins, the maximum number of failures is required. If I subtract a prime number to reach a mandatory defeat, it wins, and vice versa.
The initial score is 80, and the data is poor. If the score is less than 10000, there is 20000 of the data.
Question 2:
Question:
There is a bug, when the length is X, after a day will split into two bugs with the length of X-1, x + 1. But there will be no bugs with a length of 0. At first there was a worm with a length of 1, and how many bugs were found in N days. N <= 10000.
Problem solving process:
1. I can't make an estimation directly on the front. I first typed a table and found 10, 20, 35, 70, and other numbers, which are common combinations. Then I found the rule. The answer is:
C (n, n/2). Calculate the combination number. To avoid multiplication, you can find the number of each prime factor in the denominator of the numerator, and then calculate the approximate score.
N! There are two methods:
A: directly set 1 ~ N all number decomposition prime factor.
B: using a theorem: n! The numbers of prime factor R include N/R + N/(R2) + N/(r3) + N/(R4) ...... This proves that it will not be said. My previous blog post has, give a link: http://www.cnblogs.com/vb4896/p/3968994.html
Obviously, Method B is much faster.
The range of original question N is 100 W (it is estimated that two zeros are added ).. if O (n)'s Euler's screening method + the above method B + high-precision 8-bit pressure can only be used to run out of S of data. we can't do anything about million data, nearly one minute ~~~ (30 W abnormal digits ...).
2. The answer below is the proof of C (n, n/2) (I don't have time to think about it during the exam ):
First, the problem can be converted to finding the number of 01 strings, satisfying the number of 1 strings in any of its prefixes is not less than 0. (0 represents the length minus one, 1 represents the length plus 1, the length cannot be 0) So can be used in day1 T1 conclusion: http://www.cnblogs.com/vb4896/p/4037458.html
The number of 01 strings composed of N 0 and M 1 is C (n + M, m)-C (n + m-1 ).
So long as the number of 0 enumerated values is 0, 1, 2... n/2.
0 0 solutions: C (n, 0)
Number of 0 solutions: C (n, 1)-C (n, 0)
Number of solutions with two zeros: C (n, 2)-C (n, 1)
......
Number of n/2 0 solutions: C (n, n/2)-C (n, n/2-1)
All are C (n, n/2.
Initial score 100.
Question 3: (a very comprehensive graph topic)
Original question: the major of stupid university is electrical information. On this day, he played with the circuit at home. This circuit is divided into three parts. The leftmost part is some chaotic N points numbered 1-n, where point 1 is the output point of the input signal. They can be connected to each other using a certain length of wire. Multiple wires can be connected to one node, but the wires cannot be connected to other nodes, they may also be connected to points in part 1 through wires. Part 1 is a neat vertical M-signal amplifier numbered n + 1 ~ N + M. They are not connected to each other, but may
1 or 3rd vertices are connected. If they are connected to Point 1 (either directly or indirectly), a digital signal 1 can be output; otherwise, 0 is output. The point in Part 2 is a T-door circuit numbered N + m + 1 ~ N + M + T. Each door circuit has two input ends, one output end, and the input end is connected to the output end of a door circuit with a lower amplifier or number (the connection of this part is actually a directed acyclic graph ). The output value is the result of an exclusive or operation on two input digital signals. The output end of a vertex numbered N + M + T is connected to the final output. Now it tells you the final output result and the wires that can be connected between nodes, how do you use the shortest wire to get the final output? In addition, the final output door circuit (n + M + T) must be connected to the input signal sending point (node 1.
N ≤ l00, m ≤ 100, T ≤ 5000, W ≤ 12000
Question:
There are N points (called Class A points), numbered 1 ~ N, can be connected with a line (undirected edge). Only the signal of point 1 is 1, and the signal can be transmitted.
Has M vertex (Class B vertex), number n + 1 ~ N + M, t door (Class C point), number N + m + 1 ~ N + M + T. The input end of each door is connected to two points smaller than the number (which can be the same, which can be class B and class C points ).
If a Class B vertex is connected to 1, the output signal is 1, and if it is not connected, the output signal is 0.
The output signal of class C points is the result of two input signals after XOR.
Given B, C point connection, now you want to select some from the W link A-B or A-A undirected edge, so that point 1 and N + M + T connected, in addition, the output signal of N + M + T points is K (0 or 1), and the cost is minimal.
Problem solving process:
1. There are many restrictions on the question, but there are obvious stages. There should be two different subproblems between the AB class points and the BC class points. After taking a nap, I suddenly had a thought... the most critical breakthrough point is to find the following nature (the first difficulty in this question ):
For a class B vertex, if it reaches N + M + T (for convenience, it is called the end point, and point 1 is the start point) There are odd paths, then the signal that changes it will change the signal of the end point. If there are even numbers, it will not change. because if the signal of a point is changed, the points that can be reached from the beginning will be changed once. obviously, signals are changed only when an odd number of points are reached. In this way, Class B points can be divided into three types. One type has an odd number of paths to the end, which is called "valid points" and the other is an even number of paths, which are called "invalid points ", the rest cannot reach the end point. It is a waste point, which can be ignored directly.
2. If the signal at the end is 1, connect an effective point and the starting point based on the greedy principle. If the signal is 0, there are two cases: one is to take an invalid vertex, and the other is to take two valid vertices.
3. The second difficulty in this question is to take two valid points. That is, there is a starting point and two ending points, and the minimum cost of connecting the starting point and two ending points. set the two ends to X and Y respectively. Obviously, the shortest path from the start point to X + the shortest path from the start point to Y is incorrect, because the two shortest paths may overlap, the cost of these road sections will be calculated twice. I did not provide a solution. My approach is to run one side of Floyd first, and then enumerate the points where the path to X and Y is split for the first time. it is easy to prove that the optimal solution may only have one split point. If there are multiple branch points, the two routes between any two branch points will not affect the result if the cost is the same. If the cost is different, it is obviously better to merge them into the one with a low cost.
4. So the algorithm comes out: the number of paths from the DP end point to all B-class vertices and classify B-class vertices. K is calculated based on 0 and 1 respectively. If K = 0, you also need to enumerate which two valid points are selected and enumerate the Split points. The total complexity is O (n ^ 3 + T ).
The sample is wrong. I thought the question was wrong and I gave up the treatment without debugging the code. the question is correct, the algorithm is correct, and the program details are wrong... 0 points.
Summary:
1. space utilization should not be too tricky. As long as the memory is not exceeded, the array should be larger as much as possible.
2. for problems with large numbers, it is obvious that recurrence times out. You can create a table for small data and then find the rule... in general, the law is a multiplier relationship, a Fibonacci series, a combination number, or a Catalan number. Try it as much as possible. For example, T2.
3. complex questions can often be divided into several subproblems, which should be solved one by one to reduce the difficulty of thinking. For example, T3.
4. Be sure to debug the code carefully. I 'd rather not write it or write a lot of it, but it will be nothing.
5. Many conclusions should not only be remembered, but also be understood as how the conclusions are derived. For example, if I had not spent one night thinking about the deduction of the Catalan number in the previous T1 formula, I would never think of it. I will not deduce it. I will only draw conclusions, and the question will go down as soon as it changes.
6. Yes !! Read more Noi guides !!
Dimo (12) day1