topic:
You will get K
eggs, and can be used from one 1
to the N
total N
story building.
Each egg features are the same, if an egg is broken, you can not then it fall.
You know there is floor F
to meet 0 <= F <= N
any of the above F
eggs are broken down in the floor, from F
falling lower than its floor or floor eggs will not be broken.
Every move , you can take an egg (if you have a complete egg) and take it from any floor X
dropped (to meet 1 <= X <= N
).
Your goal is to know exactly what F
the value is.
Regardless F
of how the initial value, you determine F
the minimum number of moves value is how much?
Example 1:
Input: K = 1, N = 2 Output: 2 Explanation: Egg Drop from one floor. If it is broken, we certainly know that F = 0. Otherwise, the eggs fall from the second floor. If it is broken, we certainly know that F = 1. If it is not broken, then we know for sure F = 2. Therefore, in the worst case we need to move F 2 times to determine how much.
Example 2:
Input: K = 2, N = 6 Output: 3
Example 3:
Input: K = 3, N = 14 Output: 4
prompt:
1 <= K <= 100
1 <= N <= 10000
Ideas:
class Solution { public int superEggDrop ( int eggNum, int floorNum) { // eggNum represents a number of eggs, floorNum represents the number of floors IF (eggNum == 0 ) return 0 ; IF (eggNum ==. 1 ) return floorNum; // DP [I ] [j] denotes the i-th egg up to the j measured in step floors int [] [] DP = new new int [floorNum +. 1] [eggNum +. 1 ]; DP [ 0] [0] = 0 ; for ( int I =. 1; I <= floorNum; ++ I) { DP [I] [ 0] = 0 ; for ( int J =. 1; J <= eggNum; ++ J) { // eggs broken eggs are not broken dp [i] [j] = dp [i - 1] [j ] + DP [I -. 1] [J -. 1] +. 1 ; IF (DP [I] [J]> = floorNum) return I; } } return floorNum; } }