0.0

# FOJ/FZU/FZOJ 1550Monetary System【记忆化搜索】

Problem 1500 Monetary System

## Problem Description

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 <= 1000000000. 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.

12
2

13
2

## Source

FOJ月赛-2007年5月

n=12 当n只换一次为： 6 4 3的时候就比价值12大1为13，当然6也可以继续向下兑换，但是因为我们是举例，就不向下分了。

AC代码：

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#define ll __int64
ll output;
ll dp[1000000];//只处理10^6以下的数据记忆化，其实数据越小，越需要记忆化，反而值越大，越不需要记忆化，10^6足够了。
ll dfs(ll now)
{
if(now==0)return 0;
if(now<=1000000)
{
if(dp[now]!=0)return dp[now];
else
{
dp[now]=max(now,dfs(now/2)+dfs(now/3)+dfs(now/4));
return dp[now];
}
}
else
{
return max(now,dfs(now/2)+dfs(now/3)+dfs(now/4));
}
}
int main()
{
ll n;
while(~scanf("%I64d",&n))
{
memset(dp,0,sizeof(dp));
output=dfs(n);
printf("%I64d\n",output);
}
}


#### FZU ACM 题目分类（转自某位大神的博客）

2016-03-06 21:07:27

#### FZU FOJ 2030 括号问题【dp】||【暴搜+栈判断括号匹配】

2016-04-06 21:36:29

#### FOJ Problem 1004 Number Triangle

2016-01-14 14:46:38

#### fzu 2277 Change [第八届福建省大学生程序设计竞赛 Problem F] [线段树]

2017-07-23 15:42:42

#### FZU 1506 堆箱子

2009-12-13 14:57:00

#### 福州大学第十四届程序设计竞赛_重现赛

2017-07-19 18:06:16

#### FZOJ刷题顺序

2016-01-24 18:09:25

#### FZOJ Problem 2183 简单题

2015-03-23 22:53:11

#### FOJ2214 Knapsack problem（逆01背包）

2017-11-26 00:17:04

#### FOJ 题目分类

2009-07-30 00:06:00