Meaning
You have k an identical water polo, in an N-storey building for testing, you want to know the lowest water polo from a few floors down can let the water polo break. Because you are lazy, you want to lose at least one water polo to measure the lowest floor that the water polo just broke. (In the worst case, the water polo will not break in the attic) you can drop the water polo on one floor and test it, if the water polo is not broken, you can pick it up and continue using it.
Input
Each row you enter contains multiple sets of tests, each set as one row. Each group of tests contains two integers k and n, 1 <= k <= 100 and N is a 64-bit integer (yes, the building is really tall), and the last group of k = 0,n=0 represents the end of this set of tests that need not be addressed.
Output
For each test, the output in the worst-case scenario, the minimum number of times the water polo broke off the floor. If he is more than 63 times, the output "more than trials needed."
Ideas
The topic has been made very clear, in the worst case (that is, the last layer can be broken, but you do not know is the last layer), with a minimum number of times to know.
If you have countless water polo cases, then the minimum number of times must be a two-point method: First in the middle of the fall, if broken, indicating the target bit
Placed in the lower part, the words are not broken in the upper half. Then continue in the corresponding part of the next two points down ... Need Logn time.
But this is a limited amount of water polo, for example, if you have a water polo, you just put it down on the middle floor and if you break it, then you don't have any other balls to do the experiment. So you can only start from the first floor to throw up, the first broken floor is the target floor. The worst case scenario is to do n times.
This is still not very good to think, so to change the question, into: "To K-balloons, throw J-times, can determine the first level?" ”
In this way, the F (i, j) state can be used to represent the first I balloon, and the number of layers to be determined is lost.
For f (i, j), we do not know how many layers it can determine, assuming that the first time the ball is still in the X layer, if the ball is broken, then we spend a ball and still a fee,
We can know that f (i-1, j-1) can determine the number of layers, then we can determine x = f (i-1, j-1) + 1.
If the ball is not broken in the X layer, then we only spend the cost of one time, and I have the ball, the j-1 time can be used, then the number of layers can be determined F (i, j-1)
So, get the recursive type and push the highest level of certainty:
F (i, j) = f (i-1, j-1) + 1 + f (i, j-1);
Code
/**===================================================== * is a solution for ACM/ICPC problem * * @source: UVA -10934 Dropping water balloons * @description: DP * @author: Shuangde * @blog: blog.csdn.net/shuangde800 * @email: Zen
gshuangde@gmail.com * Copyright (C) 2013/09/09 12:49 All rights reserved. *======================================================*/#include <iostream> #include <cstdio> # Include <algorithm> #include <vector> #include <queue> #include <cmath> #include <cstring
> Using namespace std;
typedef long long Int64;
const int INF = 0X3F3F3F3F;
Int64 f[110][65]; inline void init () {memset (f, 0, sizeof (f)); for (int i = 1; i < the ++i) {for (int j = 1; j <; ++j) {f[i][j]
= F[i][j-1] + f[i-1][j-1] + 1;
int main () {init (); int k; Int64 n; while (~SCANF ("%d%lld", &k, &n) && k) {k = min (+ k); bool ok = false; for (int i = 0; I <= 63; ++i) {if (f[K][i] >= N) {printf ("%d\n", i); ok = true; break;}}
if (!ok) puts ("More than trials needed.");
return 0; }