题目传送门
/*
记忆化搜索(DFS+DP):dp[x][y] 表示x个蛋,在y楼扔后所需要的实验次数
ans = min (ans, max (dp[x][y-i], dp[x-1][i-1]) + 1);前者表示蛋没碎,则往高处(y-i)搜索
后者表示蛋碎了,往低处(i-1)方向搜索
这样写不好,每次memset (dp)就会超时:(
详细解释:http://blog.csdn.net/fulongxu/article/details/27110435
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
int dp[][MAXN];
int DFS(int x, int y)
{
if (dp[x][y]) return dp[x][y];
if (x == ) {dp[x][y] = y; return y;}
if (y <= ) {dp[x][y] = y; return y;}
int ans = INF;
for (int i=; i<y; ++i)
{
int tmp = max (DFS (x, y-i) + , DFS (x-, i-) + );
ans = min (ans, tmp);
}
return dp[x][y] = ans;
}
int main(void) //URAL 1223 Chernobyl’ Eagle on a Roof
{
//freopen ("Z.in", "r", stdin);
int n, m;
while (scanf ("%d%d", &n, &m) == )
{
if (!n && !m) break;
if (n > ) n = ;
printf ("%d\n", DFS (n, m));
}
return ;
}