11int eggDrop(
int n,
int k) {
12 std::vector<std::vector<int> > eggFloor(n + 1, std::vector<int>(k + 1));
16 for (
int i = 1; i <= n; i++) {
22 for (
int j = 1; j <=
k; j++) {
26 for (
int i = 2; i <= n; i++) {
27 for (
int j = 2; j <=
k; j++) {
28 eggFloor[i][j] = INT_MAX;
29 for (
int x = 1; x <= j; x++) {
32 result = 1 + max(eggFloor[i - 1][x - 1], eggFloor[i][j - x]);
33 if (result < eggFloor[i][j])
39 return eggFloor[n][
k];
44 cout <<
"Enter number of eggs and floors: ";
46 cout <<
"Minimum number of trials in worst case: " << eggDrop(n, k) <<
endl;
double k(double x)
Another test function.
uint64_t result(uint64_t n)