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
sarthak_8:
2015-12-31 11:55:30
Got AC !! My First DP Problem. |
|
hackerman97:
2015-12-24 18:12:08
long long int cost me 3 WA's |
|
naveenarun:
2015-12-19 06:12:44
Troubleshooting for c++:
|
|
pv:
2015-12-17 18:48:41
Okay, my approach for this question is as follows :
|
|
Akanksha Thareja:
2015-12-16 19:39:42
Yeah thanks @AlphaDecay. I got that resolved. :) |
|
AlphaDecay:
2015-12-16 18:58:09
@akanksha The input can be very large (10^9) and if you are making an array with size of the input it would cause SIGSEV. Last edit: 2015-12-16 18:58:50 |
|
Akanksha Thareja:
2015-12-16 15:17:17
Could anybody tell what could be the possible reasons for an SIGSEV error in the code for this problem? |
|
rjenni:
2015-12-09 10:44:18
Got finally an AC!
|
|
Sid:
2015-11-30 14:14:36
AC with memoization in one go. At first I thought you get 3 coins in return of 1 only a single time. The problem statement is misleading as they have not mentioned that it can be multiple times but you can guess as single time is just too simple to be on a competitive platform.
|
|
Timmy Jose:
2015-11-25 19:40:00
Damn... my Java solution got accepted but my C++ solution was causing problems due to the extra space at the end of the input file. My check while (!feof(stdin) { scanf("%lld", &n); ...} was causing the last space to trigger another run with the same value of n! I had to reset n to -1 and check that condition to exit the loop and it got AC.
|
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 |