-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1884.cpp
More file actions
27 lines (26 loc) · 772 Bytes
/
1884.cpp
File metadata and controls
27 lines (26 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution {
public:
int recursive(int k, int n, vector<vector<int>>& memo) {
if (k == 0) return 0;
if (k == 1) return n;
if (n <= 1) return n;
if (memo[k][n] != INT_MAX) return memo[k][n];
for (int i = 1; i <= n; ++i) {
memo[k][n] = min(memo[k][n], 1 + max(recursive(k - 1, i - 1, memo), recursive(k, n - i, memo)));
}
return memo[k][n];
}
int twoEggDrop(int n) {
vector<vector<int>> memo(3, vector<int>(n + 1, INT_MAX));
return recursive(2, n, memo);
}
};
// MATH SOLUTION
// class Solution {
// public:
// int twoEggDrop(int n) {
// int index = 0;
// while ((1 + index) * index / 2 < n) index++;
// return index ;
// }
// };