-
Notifications
You must be signed in to change notification settings - Fork 0
/
egg_dropping.cpp
40 lines (39 loc) · 976 Bytes
/
egg_dropping.cpp
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
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <bits/stdc++.h>
using namespace std;
int minTrials(int n, int k)
{
vector<vector<int>> dp(k + 1, vector<int>(n + 1, 0));
int m = 0;
while (dp[m][n] < k)
{
m++;
for (int x = 1; x <= n; x++)
{
dp[m][x] = 1 + dp[m - 1][x - 1] + dp[m - 1][x];
}
}
cout << "\nThe dp table made using memoization is:" << endl;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n + 1; j++)
{
cout << dp[i][j] << " ";
}
cout << endl;
}
return m;
}
int main()
{
int n, k;
cout << "Enter the number of total floors in the building: ";
cin >> k;
cout << "Enter the number of eggs available for tests: ";
cin >> n;
int res = minTrials(2, 36);
cout << "Minimum number of trials "
"in worst case with "
<< n << " eggs and " << k << " floors is ";
cout << res;
return 0;
}