Generalised Two-Egg Puzzle

前端 未结 5 1042
面向向阳花
面向向阳花 2020-12-28 11:02

Here is the Problem Description :

Suppose that we wish to know which stories in a N-story building are safe to drop eggs from, and which will cause the eggs to break

5条回答
  •  暖寄归人
    2020-12-28 11:25

    (1) Consider the case that the first drop breaks the egg. Then you can determine the breakfloor if and only if it is at most f[d-1, e-1]. Therefore you can't start higher than f[d-1, e-1] + 1 (and shouldn't start lower, of course).

    (2) If your first drop doesn't breaks the egg, you are in the case of f[d-1, e], just starting at the floor of your first drop + 1, instead of floor 1.

    So, the best you can do is to start dropping eggs at floor f[d-1, e-1] + 1 (because of (1)), and you can get up to f[d-1, e] floors higher than that (because of (2)). That's

    f[d, e] = f[d-1, e-1] + 1 + f[d-1, e]
    

提交回复
热议问题