-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathByteLandian.java
63 lines (43 loc) · 917 Bytes
/
ByteLandian.java
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package dp;
import java.util.HashMap;
public class ByteLandian {
public static long bytelandian(long n, HashMap<Long, Long> memo) {
if(n<=1)
{
return n;
}
long ans2=Integer.MIN_VALUE;
if(!memo.containsKey(n/2)) {
ans2=bytelandian(n/2, memo);
}
else
{
ans2= memo.get(n/2);
}
long ans3=Integer.MIN_VALUE;
if(!memo.containsKey(n/3)) {
ans3=bytelandian(n/3, memo);
}
else
{
ans3= memo.get(n/3);
}
long ans4=Integer.MIN_VALUE;
if(!memo.containsKey(n/4)) {
ans4=bytelandian(n/4, memo);
}
else
{
ans4= memo.get(n/4);
}
long sum = ans2+ans3+ans4;
long var = Math.max(n, sum);
memo.put(n, var);
return memo.get(n);
}
public static void main(String[] args) {
HashMap<Long,Long> map = new HashMap<>();
long ans = bytelandian(12,map);
System.out.println(ans);
}
}