5 simulation solution to a problem

Star Trek

In very special title given just two sides after 1, m-2 edges through twice, so I'm a little thought Euler road.

However, the examination did not think the split side ingenious way, played only a dfs.

Positive Solutions of each edge is split in two , the problem into two different sides omitted, so that the presence of FIG Euler path .

Of each point can be determined.

After the split in two on each side, of each point must be an even number.

Given question, there is no edge weight, the presence of self-loop.

We can discuss Category:

1. omitted from a ring, any parity does not change.

2. Delete a common edge, two points are attached parity change.

Now it requires that there are two points of an odd or even number are all of the points, and to ensure that a side can not be deleted twice.

All programs are:

1. By deleting a point corresponding to the two sides

2. Delete a loopback, and then delete just one side

3. deleting two loopback

 

 

Cutting down trees

On the test launch came very close to positive solutions to the equation, then thought for a moment can also use the number on the block.

But soon he denied himself, did not continue to push down formula.

This question points to the many parts:

For $ k = 0 $, determined directly gcd.

For $ k = 1 $, a discarded, seeking other gcd, try to use a divisor gcd update answers in the case of qualifying.

For $ k> = a_max * n-sum $, i.e. k is selected to meet at least the largest, may be $ O (1) $ calculated.

For $ a_i <5e5 $, violence enumeration.

Correct answer is number theory block the launch of the equation is:

$\sum \limits_{i=1}^{n} \lceil \frac{a_i}{d} \rceil <= \lfloor \frac{k+ \sum \limits_{i=1}^{n} a_i}{d} \rfloor$

Solutions of the biggest d.

Found molecule to the right of the equal sign is a constant value , is C,

Knowledge of number theory, we know the value of the block to the right of only $ 2 \ sqrt {C} $ a.

Obviously when d greater value on the left side of the smaller, more able to update the answer,

So the biggest d each enumeration value in line with, and try to update the answer to.

 

Super tree

See the data range, although the examination room thought dp,

But no way to design a state, let alone transfer.

dp state design of very God.

$ f (i, j) $ i- super tree set, the presence j article does not intersect at any point the number of program paths.

For convenience, we set num = f [i-1] [l] * f [i-1] [r].
do nothing:

$ f [i] [l + r] + = num $ --- 1
plus only the root path:

$ f [i] [l + r + 1] + = num $ --- 2
connected to the left / right one path:

$ f [i] [l + r] + = num * (l + r) * Cause $ 2 * 2 --- 3 is bi-
around communication:

$ f [i] [l + r-1] + = num * l * r * 2 $ --- 4
communicate with left / right two paths:

$ F [i] [l + r-1] + = num * (l * (l-1) + r (r-1)) $ --- 5 It * 2, but the number of combinations eliminate / 2

Initial $ f [1] [1] = 1, f [1] [0] = 1 $
certain $ f [n] [1] $
consider the actual meaning of j, j may risen to $ 2 ^ i $.
However, according to the transfer dp, $ f [n] [1 ] $ up to [n-i + 1] $ transferred from $ f [i].
So we complexity is $ O (n ^ 3) $ .

Guess you like

Origin www.cnblogs.com/skyh/p/11209265.html