-
Notifications
You must be signed in to change notification settings - Fork 13
/
eggDrop.cpp
executable file
·47 lines (47 loc) · 1.08 KB
/
eggDrop.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
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
int a[15][5009], p[15];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t, i, j, n, h, k, x, res;
p[0] = 1;
for(i = 1; i < 15; i++)
p[i] = p[i-1]*2;
cin >> t;
while(t--)
{
cin >> n >> h;
for(x = 14; x >= 0; x--)
{
if(p[x] <= h)
break;
}
x++;
if(n >= x)
cout << x << '\n';
else
{
for(i = 1; i <= n; i++)
{
for(j = 0; j <= h; j++)
{
if(j == 0 || j == 1 || i == 1)
a[i][j] = j;
else
{
a[i][j] = INT_MAX;
for(k = 1; k <= j; k++)
{
res = 1 + max(a[i-1][k-1],a[i][j-k]);
a[i][j] = min(res,a[i][j]);
}
}
}
}
cout << a[n][h] << '\n';
}
}
return 0;
}