-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheggFall.java
More file actions
30 lines (24 loc) · 733 Bytes
/
eggFall.java
File metadata and controls
30 lines (24 loc) · 733 Bytes
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
import java.util.Scanner;
public class eggFall {
public static int eggDrop(int n, int k) {
int[][] floors = new int[k + 1][n + 1];
for (int d = 1; d <= k; d++) {
for (int e = 1; e <= n; e++) {
floors[d][e] = 1
+ floors[d - 1][e - 1]
+ floors[d - 1][e];
if (floors[d][e] >= k) {
return d;
}
}
}
return -1;
}
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int eggs = scn.nextInt();
int height = scn.nextInt();
System.out.println(eggDrop(eggs, height));
scn.close();
}
}