I agree with the Roc6212, this is generally a searching problem, binary search tree seems most efficient. As shown below, a 30 floor building requires a 5 levels tree, which suggests a maximum of 5 tests needed.
16
8
4 12 .................
2 6 10 14
1 3 5 7 9 11 13 15
Suppose the highest floor = X. Current testing floor = T
As every failed test(X<T) that consumes the egg will result in traversing the left tree, In the case that X<=1, the four left traversals will break all four eggs and left 1 untested.(I assume the egg can also be broken at level 1 then we still need to test it). Although in other cases when X>1, there will be at least one right traversal so 4 eggs is enough.
Hence, an improved way to build the tree is eliminate the leftmost element, so that the last traversal cannot be left.
15
7
3 11 .................
1 5 9 13
2 4 6 8 10 12 14
In this scenario we can choose 15 at the beginning, on the left tree we have 14 floors, on the right side we have 15 floors. And the maximum floors that we can test for 4 eggs is exactly 30 floors.
So generally the maximum number of floors that can be test in one round(one tree) is 2m+1-2, for n>2m+1-2, we can divided into several rounds: 1 to 2m+1-2, 2m+1-1 to 2m+2-4, ...... Notice if X> 2m+1-2, the first round test will preserve all the eggs. Hence we can test each round sequentially and each round will have full m eggs to test.
/***********Update******************/
In fact, for situation that n>2m+1-2, we can use an unbalance binary tree(right heavy) as long as it satisfies the condition that for all the possible paths, the left traversals do not exceed m. I think this method can always beat the previous one(sequential round). And the analysis of average steps is a more complicated.
For general case, we will need to first calculate the total depth of the tree. Let nm(d) denotes the items contained in our tree, m = eggs, d = depth, the tree rooted at depth 1.
Once we get the depth, we can calculate the size of left tree and get which testing floor we should choose. And the current test floor should be 1+nm-1(d-1) .