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
|
||||||||||||||
2015-05-19 08:08:23 SHRINIKET ACHARYA
MY code is running well up to 8 digits but when I run for a 9 digit number it gives me runtime error on ideone. can anyone tell me what is wrong in my code .? http://www.spoj.com/submit/COINS/id=14277516 Last edit: 2015-05-20 19:47:33 |
||||||||||||||
2015-04-16 10:00:57 thelazycoder
Great question . Use this question to learn alot. Try learning Map for this :D |
||||||||||||||
2015-04-12 18:36:39 Madhav
AC!! |
||||||||||||||
2015-04-05 12:40:00 Gautam K Sharma
My First dp . Done without using maps :D |
||||||||||||||
2015-04-01 22:48:42 jaswin kaur
My first dp problem *_* learned a lottt !!! feeling great :D thanku spoj :) |
||||||||||||||
2015-03-29 17:29:16 Gohan
My First DP..!! Memoization+Mapping. Use long long unsigned if range problem persists. |
||||||||||||||
2015-03-16 13:52:42 Ayon Das
First tym a DP prblem gt AC in one go :) Piece of cake. |
||||||||||||||
2015-03-06 08:35:44 Anshuman Suri
Good question :) Got to learn a bit about maps ;) |
||||||||||||||
2015-02-21 18:46:13 abhishek gupta
HOW TO KNOW THE NUMBER OF TEST CASES? re(vamsi): you have to read until EOF. Check the documentation of the language you use to know how to read till EOF. Last edit: 2015-02-21 19:02:06 |
||||||||||||||
2015-02-17 18:58:10 Vivek
Do it carefully.A lot to learn from this problem. First DP and got to know how awesome DP is. in C++ : MAP+ Recursion+ DP |