来个递归版本
C++ 代码
#include <iostream>
#include <algorithm>
using namespace std;
const int M = 11,N = 101;
vector<vector<int>> dp(N,vector<int>(M,-1));
int m ,n;
int dfs(vector<vector<int>> &dp,int level, int egg){
if(dp[level][egg] != -1) return dp[level][egg];
dp[level][egg] = dfs(dp,level,egg-1);
for(int i = 2; i <= level;i++){
dp[level][egg] = min(dp[level][egg],max(dfs(dp,i-1,egg-1),dfs(dp,level - i,egg))+1);
}
return dp[level][egg];
}
int main(){
while(cin >> n >> m){
for(int i = 0; i<=n;i++) dp[i][1] = i;
for(int j = 1 ; j <= m; j++) dp[1][j] = 1;
dfs(dp,n,m);
cout << dp[n][m] << endl;
}
return 0;
}