AcWing 1048. 鸡蛋的硬度
原题链接
中等
作者:
Freya
,
2020-06-15 17:51:34
,
所有人可见
,
阅读 608
算法1
时间复杂度 $O(n^2m)$
C++ 代码
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 110, M = 11;
int n, m;
int f[N][M];
int main() {
while(cin >> n >> m) {
for(int i = 1; i <= n; ++i) f[i][1] = i;
for(int i = 1; i <= m; ++i) f[1][i] = 1;
for(int i = 2; i <= n; ++i)
for(int j = 2; j <= m; ++j) {
f[i][j] = f[i][j - 1];
for(int k = 1; k <= i; ++k)
f[i][j] = min(f[i][j], max(f[k - 1][j - 1], f[i - k][j]) + 1);
}
cout << f[n][m] << endl;
}
return 0;
}