You have k exactly the same water polo in a building on n floors, you want to know the water polo from a few floors down the drop can let the water polo broken. Because you are very lazy, you want to lose the ball at least times to measure the lowest floor where the ball just broke. (In the worst case, the water polo won't be broken on the top floor.) You can leave the water polo in a certain floor for testing. If the water polo is not broken, you can pick it up and continue using it. Each line of Input contains multiple groups of tests, each of which is one row. Each group of tests contains two integers, k and n, 1 <= k <= 100, and n is a 64-bit integer (yes, this building is indeed very high ), the last group k = 0, n = 0 indicates the end, and this group of tests does not need to be processed. Output: For each test, the minimum number of times the water bulb breaks the floor is measured in the worst case. If it is More than 63 times, the output "More than 63 trials needed. "The question of thinking has been clearly explained. In the worst case (that is, the last layer can be broken, but you don't know it is the last layer), you can know it in the least number of times. Assuming that you have no more water balls, the minimum number of times must be two points: first, drop down in the middle. If it is broken, it indicates that the target is located in the lower half, if it is not broken, it is in the upper part. And then continue in the corresponding part ...... Logstores are required n times. However, the number of water balls for this question is limited. For example, if there is only one water polo, you can place the ball directly on the middle floor. If you break the ball, then you will not continue the experiment. Therefore, you can only continue to drop from the first floor, and the first floor to be broken is the target floor. So the worst case is to do it N times. In this case, I still don't really want to think about it, so I need to convert the problem into: "How many layers can I determine if I lose j balloons to k ?" In this way, the f (I, j) state can be used to represent the I-th balloon. the maximum number of layers determined by j is lost. For f (I, j), we don't know at most how many layers it can determine. If the ball is still in the x Layer for the first time, so we spent 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 at Layer x, we only spend the cost of one time, and I still have the ball, the J-1 can be used, so with these layers that can be determined f (I, J-1) So, get the recursive formula, the maximum number of layers that can be determined: f (I, j) = f (I-1, J-1) + 1 + f (I, J-1); Code
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 20 21 22 23 24 25 26 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 44 45 46 48 49 50 51 52 53 54 55/** ====================== ========================== * This is a solution for ACM/ICPC problem ** @ source: uva-10934 Dropping water balloons * @ description: dp * @ author: shuangde * @ blog: blog.csdn.net/shuangde800 * @ email: zengshuangde @ 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 int64; const int INF = 0x3f3f3f3f; int64 f [110] [65]; inline void init () {memset (f, 0, sizeof (f )); for (int I = 1; I <64; ++ I) {for (int j = 1; j <64; ++ 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 (63, 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 63 trials needed.");} return 0;} CODE piece from CODE