-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathprog3.java
More file actions
33 lines (30 loc) · 1010 Bytes
/
prog3.java
File metadata and controls
33 lines (30 loc) · 1010 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
31
32
33
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
class Codechef
{
private static Map<Integer, Long> table = new HashMap<Integer, Long>();
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
String line;
while ((line = in.readLine()) != null) {
int n = Integer.parseInt(line);
out.println(maxDollars(n));
}
out.flush();
}
public static long maxDollars(int n) {
if (n < 12)
return n;
if (table.containsKey(n))
return table.get(n);
long maxDollarsOfNCoins = maxDollars(n/2)+maxDollars(n/3)+maxDollars(n/4);
table.put(n, maxDollarsOfNCoins);
return maxDollarsOfNCoins;
}
}