We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2db8a3b commit ea0b51dCopy full SHA for ea0b51d
887. Super Egg Drop (Leetcode)
@@ -0,0 +1,32 @@
1
+class Solution {
2
+public:
3
+ int compute(int n, int k, vector<vector<int>> &DP) {
4
+ if(n == 1 || k == 1 || k == 0) return k;
5
+ if(DP[n][k] != -1) return DP[n][k];
6
+ int low = 1;
7
+ int high = k;
8
+ int ans = INT_MAX;
9
+ while(low <= high) {
10
+ int mid = low + (high - low) / 2;
11
+ int A = 1 + compute(n - 1, mid - 1, DP);
12
+ int B = 1 + compute(n, k - mid, DP);
13
+ ans = min(ans, max(A, B));
14
+ if(A < B) {
15
+ low = mid + 1;
16
+ }
17
+ else if(A > B) {
18
+ high = mid - 1;
19
20
+ else {
21
+ break;
22
23
24
+ DP[n][k] = ans;
25
+ return DP[n][k];
26
27
+ int superEggDrop(int n, int k) {
28
+ vector<vector<int>> DP(n + 1, vector<int>(k + 1, -1));
29
+ return compute(n, k, DP);
30
31
+
32
+};
0 commit comments