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.

一开始开的1e9数组果断CE,然后开成1e8,对大于1e8的元素进行递归处理,小于1e8的将结果存到数组。

 #include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn=+;
LL f[maxn];
LL g(LL n){
if(n<=) return f[n];
return max(n,g(n/)+g(n/)+g(n/));
}
int main()
{
f[]=;
for(LL i=;i<=maxn-;++i){
f[i]=max(i,f[i/]+f[i/]+f[i/]);
}
LL n;
while(scanf("%lld",&n)==){
if(n<=)
printf("%lld\n",f[n]);
else
printf("%lld\n",g(n)); }
return ;
}

Spoj-COINS-记忆化dp的更多相关文章

  1. Google Code Jam 2009, Round 1C C. Bribe the Prisoners (记忆化dp)

    Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. ...

  2. UVA - 11324 The Largest Clique 强连通缩点+记忆化dp

    题目要求一个最大的弱联通图. 首先对于原图进行强连通缩点,得到新图,这个新图呈链状,类似树结构. 对新图进行记忆化dp,求一条权值最长的链,每一个点的权值就是当前强连通分量点的个数. /* Tarja ...

  3. cf835(预处理 + 记忆化dp)

    题目链接: http://codeforces.com/contest/835/problem/D 题意: 定义 k 度回文串为左半部分和右半部分为 k - 1 度的回文串 . 给出一个字符串 s, ...

  4. cf779D(记忆化dp)

    题目链接: http://codeforces.com/problemset/problem/799/D 题意: 给出两个矩阵边长 a, b, 和 w, h, 以及一个 c 数组, 可选择 c 数组中 ...

  5. Codeforces1107E Vasya and Binary String 记忆化dp

    Codeforces1107E 记忆化dp E. Vasya and Binary String Description: Vasya has a string \(s\) of length \(n ...

  6. POJ 1088 滑雪(简单的记忆化dp)

    题目 又一道可以称之为dp的题目,虽然看了别人的代码,但是我的代码写的还是很挫,,,,,, //看了题解做的简单的记忆化dp #include<stdio.h> #include<a ...

  7. POJ 1088 滑雪 记忆化DP

    滑雪 Time Limit: 1000MS   Memory Limit: 65536K       Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度 ...

  8. BNU 25593 Prime Time 记忆化dp

    题目链接:点击打开链接 题意: 一个游戏由3个人轮流玩 每局游戏由当中一名玩家选择一个数字作为開始 目的:获得最小的得分 对于当前玩家 O .面对 u 这个数字 则他的操作有: 1. 计分 u +1 ...

  9. [luogu]P1514 引水入城[搜索][记忆化][DP]

    [luogu]P1514 引水入城 引水入城 题目描述在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠.该国的行政区划十分特殊,刚好构成一个N 行M 列的矩形 ,如下图所示,其中每个格 ...

  10. 记忆化dp博弈

    题:http://poj.org/problem?id=2068 题意: 有两个队伍A,B,每个队伍有N个人,交叉坐.即是A(1,3,5,7.....)B(2,4,6,8....).告诉你每个mi(1 ...

随机推荐

  1. @FindBy、@FindBys、@FindAll的区别

    原文地址http://blog.csdn.net/tea_wu/article/details/21080789 selenium-webdriver中获取页面元素的方式有很多,使用注解获取页面元素是 ...

  2. 在vue中使用express-mock搭建mock服务

    首先安装 nodemon ,如果是全局安装,那么所有的项目都可以使用mock服务 npm install nodemon 再安装express-mockjs npm i -D express-mock ...

  3. maven工具使用之常用maven命令(二)

    1.创建java web项目: # mvn archetype:generate -DgroupId=com.igoodful.sdxs      -DartifactId=hubu  -Darche ...

  4. [转]linux内核分析笔记----内存管理

    转自:http://blog.csdn.net/Baiduluckyboy/article/details/9667933 内存管理,不用多说,言简意赅.在内核里分配内存还真不是件容易的事情,根本上是 ...

  5. Django 部署(Apache下)

    前言: 因为需要在服务器下运行python脚本,所以需要搭建Django服务器.所以将自己的学习过程也记录下来,方便日后查阅. 本文环境如下: Ubuntu 16.04  python2.7 Apac ...

  6. pycharm 小知识

    pycharm使用过程小知识: 1.pycharm定义项目或脚本抬头模版:setting ——Editor——File and Code Templates,右侧选择Python Script: 2. ...

  7. MLlib1.6指南笔记

    MLlib1.6指南笔记 http://spark.apache.org/docs/latest/mllib-guide.html spark.mllib RDD之上的原始API spark.ml M ...

  8. 20145321 《Java程序设计》第10周学习总结

    20145321 <Java程序设计>第10周学习总结 教材学习内容总结  网络编程:网络编程的实质就是两个(或多个)设备(例如计算机)之间的数据传输. IP地址:为了能够方便的识别网络上 ...

  9. libcstl中的list没法插入自定义数据

    一开始运行出错,开启debug以后发现在push自定义对象的时候调试器提示找不到一个叫/XXX/XXXX/XXXX/libcstl-2.3.0/src/cstl_list_private.c</ ...

  10. 快用Visual Studio(二)- 界面,功能区与命令面板

    Layout Editing Explorer Saving Searching Command Palette File Navigation File and Folder Based Files ...