Submit | All submissions | Best solutions | Back to list |
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.
Added by: | Tomek Czajka |
Date: | 2005-05-03 |
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 |
hide comments
|
||||||||||||||
2019-11-21 11:58:05
How can you do recursion with memoization when the n is really big? creating array[1000000000] will give you error.. |
||||||||||||||
2019-10-25 11:22:39
hey guys pls help me what is the meaning of /home/UrwtJs/cc0wNpVQ.o: in function `_GLOBAL__sub_I_dp': prog.cpp:(.text.startup+0x117): relocation truncated to fit: R_X86_64_PC32 against `.bss' prog.cpp:(.text.startup+0x135): relocation truncated to fit: R_X86_64_PC32 against `.bss' collect2: error: ld returned 1 exit status |
||||||||||||||
2019-10-24 07:14:54
Easy one. Thanks to @rmcr714 |
||||||||||||||
2019-10-15 08:18:48
Be careful using int instead of long long int |
||||||||||||||
2019-09-16 10:43:50
ac in one go!! yeah! |
||||||||||||||
2019-09-13 10:09:18
prefetch 10million coins' results, use this part as cache; recursively solve the big number like 1billion, since we cached first 10 million results, actually, it just takes 8 steps (log100) to get the 1billion coin's solution, pretty fast:) |
||||||||||||||
2019-08-26 08:55:10
though only DP' is accepted ... |
||||||||||||||
2019-08-16 18:25:31
Recursion with memoization |
||||||||||||||
2019-08-08 19:52:07
DP is not efficient here, because it is not needed to solve all previous subproblems (for n, we dont need all 1, 2, 3... n-1 solutions). The best approach is to use recursion with memoization. Cheers! |
||||||||||||||
2019-08-01 13:19:27
how to take input with javascript |