COINS  Bytelandian gold coins
In Byteland they have a very strange monetary system.
Each Bytelandian gold coin has an integer number written on it. A coin n can be exchanged in a bank into three coins: n/2, n/3 and n/4. But these numbers are all rounded down (the banks have to make a profit).
You can also sell Bytelandian coins for American dollars. The exchange rate is 1:1. But you can not buy Bytelandian coins.
You have one gold coin. What is the maximum amount of American dollars you can get for it?
Input
The input will contain several test cases (not more than 10). Each testcase is a single line with a number n, 0 <= n <= 1 000 000 000. It is the number written on your coin.
Output
For each test case output a single line, containing the maximum amount of American dollars you can make.
Example
Input: 12 2 Output: 13 2
You can change 12 into 6, 4 and 3, and then change these into $6+$4+$3 = $13. If you try changing the coin 2 into 3 smaller coins, you will get 1, 0 and 0, and later you can get no more than $1 out of them. It is better just to change the 2 coin directly into $2.
hide comments
jllew:
20181014 22:29:03
consider int overflow for big input 

adipat:
20181011 19:50:29
Classic DP problem. If you're using C++, consider using vector, it has a larger capacity so you can precompute more values. I used bottom up DP. You can't compute upto 10^9 values because it's too slow but you can definitely compute upto 10^8 without any considerable loss in speed. 

suryacodes:
20181010 18:24:36
And it said accepted !! 

harry_shit:
20180919 16:19:35
real happiness is getting AC. :) 

anant6025:
20180913 22:33:49
Wohoo finally!


v_ns:
20180909 17:53:01
Very interesting problem, you can't store values upto 10^9 in array, think of using DP till values you can precompute, then use the old recursion technique. 

anupam125:
20180907 19:44:17
how 120 for n=100 

strikas:
20180907 08:46:48
use map instead of array, dp and recursion Last edit: 20180907 08:47:20 

vipul_17:
20180807 16:17:51
used unsigned long int for array in c;


ashish malgawa:
20180804 11:04:40
Do we need to take in input number of test cases also? 
Added by:  Tomek Czajka 
Date:  20050503 
Time limit:  9s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: NODEJS PERL6 VB.NET 
Resource:  Purdue Programming Contest Training 