@@ -13,18 +13,18 @@ private static int minTrials(int n, int m)
13
13
for (int i = 1 ; i <= n ; i ++)
14
14
{
15
15
eggFloor [i ][0 ] = 0 ; // Zero trial for zero floor.
16
- eggFloor [i ][1 ] = 1 ; // One trial for one floor
16
+ eggFloor [i ][1 ] = 1 ; // One trial for one floor
17
17
}
18
18
19
- // j trials for only 1 egg
19
+ // j trials for only 1 egg
20
20
21
- for (int j = 1 ; j <= m ; j ++)
21
+ for (int j = 1 ; j <= m ; j ++)
22
22
eggFloor [1 ][j ] = j ;
23
23
24
24
// Using bottom-up approach in DP
25
25
26
- for (int i = 2 ; i <= n ; i ++)
27
- {
26
+ for (int i = 2 ; i <= n ; i ++)
27
+ {
28
28
for (int j = 2 ; j <= m ; j ++)
29
29
{
30
30
eggFloor [i ][j ] = Integer .MAX_VALUE ;
@@ -33,22 +33,21 @@ private static int minTrials(int n, int m)
33
33
result = 1 + Math .max (eggFloor [i -1 ][x -1 ], eggFloor [i ][j -x ]);
34
34
35
35
//choose min of all values for particular x
36
- if (result < eggFloor [i ][j ])
37
- eggFloor [i ][j ] = result ;
36
+ if (result < eggFloor [i ][j ])
37
+ eggFloor [i ][j ] = result ;
38
38
}
39
39
}
40
40
}
41
+
41
42
return eggFloor [n ][m ];
42
-
43
43
}
44
44
45
45
//testing program
46
46
public static void main (String args [])
47
47
{
48
- int n = 2 , m = 4 ;
49
- //result outputs min no. of trials in worst case for n eggs and m floors
50
-
51
- int result = minTrials (n , m );
52
- System .out .println (result );
48
+ int n = 2 , m = 4 ;
49
+ //result outputs min no. of trials in worst case for n eggs and m floors
50
+ int result = minTrials (n , m );
51
+ System .out .println (result );
53
52
}
54
53
}
0 commit comments