We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#include #include #include <limits.h>
using namespace std;
int superEggDrop(int k, int n) { vector<vector> ans(k + 1, vector(n + 1, 0));
for (int i = 1; i <= k; i++) { for (int j = 1; j <= n; j++) { if (i == 1) { ans[i][j] = j; } else if (j == 1) { ans[i][j] = 1; } else { int low = 1, high = j; while (low + 1 < high) { int mid = (low + high) / 2; int broken = ans[i - 1][mid - 1]; // Egg breaks int notBroken = ans[i][j - mid]; // Egg does not break if (broken > notBroken) { high = mid; } else { low = mid; } } // check both low and high ans[i][j] = 1 + min(max(ans[i - 1][low - 1], ans[i][j - low]), max(ans[i - 1][high - 1], ans[i][j - high])); } } } return ans[k][n];
}
The text was updated successfully, but these errors were encountered:
No branches or pull requests
#include
#include
#include <limits.h>
using namespace std;
int superEggDrop(int k, int n) {
vector<vector> ans(k + 1, vector(n + 1, 0));
}
The text was updated successfully, but these errors were encountered: