By the UVa10934 (dynamic programming) triggered thoughts

This question has many solution, at the beginning of this question feel very lost, and then looked at other people's blog, found that many are stereotyped, some directly copied the solution of the problem purple book,

I am a konjac, can not read, so very Meng ...... then continue to work hard to find information on the Internet, finally, I know this kind of problem, the name of such problems is called the eagle egg problem,

We learned a lot through the years 2004 IOI National Team Zhu Chenguang papers.

There were a bunch of M eagle egg, a professor wants to study these stiffness eagle eggs E. He is by constantly
Upstairs from an N layer throw down eagle egg E is determined. When falling from the egg E Eagle floor and the floor
When is not broken, but the first (E + 1) layer floor and above to be broke when falling. If the eagle egg not fall
Broken, can continue to use; but if all broken egg eagle still undetermined E, which is obviously a real failure
Experience. Professor hopes the experiment was a success.
For example: if the egg Eagle i.e. floor and broke down from layer 1, E = 0; if N eagle eggs falling from floor not broken,
E = N.
It is assumed that all of the eagle have the same degree of egg hard. The number of eggs to Eagle given number of floors N. M
E minimum number required to determine the worst-case requirements.
This question seems to find half but we found that there is a limit on the number of eagle eggs, so you can not simply use a binary search to solve,
Define a state d (i, j) denotes the number of E i with a minimum of required eggs to determine the worst case j floor
Difficult to draw d (i, j) = min {max {d (i-1, w-1), d (i-1, jw)} + 1 | 1 <= w <= j} (state transition equation derivation omitted, it is recommended to see the papers)
This method requires the case of O (n ^ 3), the time can not afford, but also optimize it? Yes, this question is similar to binary search, but
Limit the number of eagle eggs, we might assume that the number of infinity eagle egg it? So that we can use binary search to find an answer quickly,
Then we know that when M> = log (n + 1) we use binary search directly on the line, when M <log (n + 1) we use the dynamic programming, and we
Reducing the number of states can be optimized algorithm to O (n ^ 2logn), but also to optimize it? Still, this time we optimize the transfer of state
We can send to d (i, j)> d (i, j-1) and then draw a diagram:
(FIG. 2, so that ① is f (i-1, w-1) image, ② as f (i, jw) images (both with a line segment connecting two adjacent points), ③ is the max {f (i -1, w-1), f (i, jw)} + 1 image)
Wbest found to meet the 3 position this shape characteristic lines can be subjected to third (uncertain), and we will drop the state transition would be O (logn), the overall time complexity is O (n (logn ) ^ 2)
But also optimize it? Of course you can, but we can see the paper on the line, I will not set forth the method of the optimization, dynamic programming can be seen that there are many ways to improve efficiency (defined state, the state transition equation,
The total number of states, the number of decision-making, etc.), for UVa10934, the above methods are not able to solve the problem, and why? Because the building is too high (2 ^ 64), exceeded the memory limits,
So we can only modify the definition of the state, which is specifically discussed in the paper, where I will talk about the simple.
We define D (i, j) represents the highest floors of the building by i times j ball experiments tested (herein refers to the most highest), does not affect the state of the layer to take k (where k is randomly taken transfer equation), it is assumed broken, then the height H corresponding to the hardness E must satisfy H <W, so we see d (i-1, j-1) the maximum number of layers (which must meet optimal subproblems - most Yuko problem), if not broken, then we know that H> = W so we
See d (i-1, j) can reach the maximum number of layers, the final total number of layers is d (i, j) = d (i-1, j-1) + d (i-1, j) + 1 (Figure know "1," the origin).

 Code code repository lrj see it!

Guess you like

Origin www.cnblogs.com/yifeiWa/p/11294225.html