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
|
||||||||||||||
2018-09-07 19:44:17
how 120 for n=100 |
||||||||||||||
2018-09-07 08:46:48
use map instead of array, dp and recursion Last edit: 2018-09-07 08:47:20 |
||||||||||||||
2018-08-07 16:17:51
used unsigned long int for array in c; DP,recursion and memoization. |
||||||||||||||
2018-08-04 11:04:40 ashish malgawa
Do we need to take in input number of test cases also? |
||||||||||||||
2018-08-01 06:23:29
Got it !! 50, 33 and 25 will have a further optimal solution 57, 36 and 27 respectively. That's why the output is 120 (57+36+27) Last edit: 2018-08-01 06:24:12 |
||||||||||||||
2018-07-31 18:22:32
How is the output 120 for the input 100? shouldn't it be 108(50+33+25)? |
||||||||||||||
2018-07-30 09:20:31
first dp to be ac in a go!! |
||||||||||||||
2018-07-27 09:27:17
Computing solutions lazily is significantly faster than preprocessing. |
||||||||||||||
2018-07-23 12:18:29
AC in one go !!! Thank you @castor21 . |
||||||||||||||
2018-07-23 08:59:28
I am new to dp, and I tried to use the top-down recursive memo array of size 10^9 when I realized the problem of memory. Also part of the dp array is seldom used. But is there a way to solve the problem with this approach (instead of the suggested bottom-up dp array + recursion approach) ? |