First think about the special situation, if there is only one balloon, we have to determine the height can only from the bottom to the next layer of testing, because if the balloon burst, it will not be able to measure the hardness of the balloon.
If there are countless balloons, then you can use a two-point method to determine.
Generally, a D (i, j) is used to indicate the maximum height of the floor that can be determined by the I-Balloon experiment J-Th.
Let's assume that the first balloon is dropped from level K,
- If the balloon burst, then the rest of the i-1 a balloon experiment j-1 times, to be able to determine the hardness of the balloon in the K-1 layer below. So this k Max takes D (i-1, j-1) +1
- The balloon does not explode, then the first 1~k layer is completely out of control, I j-1 the rest of the balloon test will go directly to the test on the line, up to test D (I, j-1) layer
So D (i, j) = d (i-1, j-1) + 1 + d (i, j-1)
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 7typedef unsignedLong LongLL;8 9 Const intMAXN = -+1;Ten Const intMAXM = -; One A LL A[MAXN][MAXM]; - - intN; the LL H; - - intMain () - { + for(inti =1; i < MAXN; i++) - for(intj =1; J < Maxm; J + +) +A[I][J] = a[i-1][j-1] +1+ a[i][j-1]; A at while(CIN >> N >> H &&N) - { - inti; - for(i =1; i < MAXM; i++)if(A[n][i] >= h) Break; - if(I < MAXM) printf ("%d\n", i); - ElsePuts"More than trials needed."); in } - to return 0; +}
code June
UVa 10934 DP dropping water balloons