FZU 1500 Monetary System(深搜+打表)

来源:互联网 发布:小米盒子语音软件 编辑:程序博客网 时间:2024/06/13 00:20

Problem 1500 Monetary System
Accept: 417 Submit: 1263
Time Limit: 1000 mSec Memory Limit : 32768 KB

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.
Sample Input

12
2
Sample Output

13
2

题目大意:你有一种价值为n金币,这种金币你可以在该国家银行换为3个金币:n/2,n/3,n/4。那么换完之后你所拥有的金币价值就是后来的这三种金币之和,当然你也可以选择不换。另外这种金币与美元的兑换比率是1:1。问你最多能得到多少美元。

思路:先把利用深搜把1000的表打出来。接着深搜就可以了,只要被分成的新的金币小于1000,那么直接返回数组中对应的值就OK了。具体看AC代码吧。

AC代码:

#include<cstdio>#include<algorithm>#include<cmath>#include<vector>#define ll __int64using namespace std;__int64 a[1005]={1,2,3,4,5,6,7,8,9,10,11,13,13,14,15,17,17,19,19,21,22,23,23,27,27,27,28,30,30,32,32,35,36,36,36,41,41,41,41,44,44,46,46,48,49,49,49,57,57,57,57,57,57,60,60,63,63,63,63,68,68,68,69,74,74,76,76,76,76,76,76,87,87,87,87,87,87,87,87,92,93,93,93,98,98,98,98,101,101,104,104,104,104,104,104,119,119,119,120,120,120,120,120,120,120,120,120,129,129,129,129,134,134,134,134,134,134,134,134,144,144,144,144,144,144,147,147,155,155,155,155,160,160,160,161,161,161,161,161,161,161,161,161,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,193,193,197,197,197,197,197,197,207,207,207,207,207,207,207,207,212,212,212,212,221,221,221,221,221,221,221,221,221,222,222,222,250,250,250,250,250,250,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,276,276,276,276,276,276,276,276,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,304,304,304,305,305,305,305,305,305,305,305,305,314,314,314,314,327,327,327,327,327,327,327,327,337,337,337,337,337,337,341,341,341,341,341,341,341,341,341,341,341,341,341,341,341,341,341,341,391,391,391,391,391,391,391,391,391,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,405,405,405,405,419,419,419,419,419,419,419,419,419,419,419,419,439,439,439,439,439,439,439,439,439,439,439,439,439,439,439,439,447,447,447,447,447,447,447,447,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,473,473,473,473,473,473,524,524,524,524,524,524,524,524,524,524,524,524,533,533,533,533,533,533,533,533,533,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,641,641,641,641,641,641,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,668,668,668,668,668,668,668,668,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,709,709,709,709,709,709,709,709,709,709,709,709,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,724,724,724,724,724,724,724,724,724,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,851,851,851,851,851,851,851,851,892,892,892,892,892,892,892,892,892,892,892,892,892,892,892,892,892,892,892,892,892,892,892,892,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,930,943,943,943,943,943,943,943,943,943,943,943,943,943,943,943,943,994,994,994,994,994,994,994,994,994,995,995,995,995,995,995,995,995,995,995,995,995,995,995,995,995,995,995,995,995,995,995,995,995,995,995,995,1009,1009,1009,1009,1009,1009,1009,1009,1009,1009,1009,1009,1101,1101,1101,1101,1101,1101,1101,1101,1101,1101,1101,1101,1101,1101,1101,1101,1101,1101,1101,1101,1101,1101,1101,1101,1123,1123,1123,1123,1123,1123,1123,1123,1123,1123,1123,1123,1123,1123,1123,1123,1123,1123,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1128,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1257,1258,1258,1258,1258,1258,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1279,1350,1350,1350,1350,1350,1350,1350,1350,1350,1350,1350,1350,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370,1370};ll dfs(ll n){    if(n==0)    {        return 0;    }    if(n<1000)    {        return a[n-1];    }    n=max(n,(dfs(n/2)+dfs(n/3)+dfs(n/4)));    return n;}int main(){    __int64 n;    //FILE *fp;       // fp=fopen("C:\\Users\\linlinsong\\Desktop\\out.txt","w");     while(~scanf("%I64d",&n))      //for(int i=1;i<=1000;i++)      {        ll re=dfs(n);        printf("%I64d\n",re);       // printf("%I64d\n",re);       //fprintf(fp,"%I64d,",re);    }        //write("AAAAA",6,1,fp);    //fclose(fp);    return 0;}
1 0
原创粉丝点击