spoj 346

当一个数大于等于12  那分别处以2, 3, 4之后的和一定大于本身    但是直接递归会超时    然后发现有人用map存了   膜拜.....

#include <cstdio>
#include <map>
#include <algorithm>

using namespace std;

map<int, long long> d;

long long cc(int x)
{
    if(x < 12)
        return x;
    if(d[x] != 0)
        return d[x];
    else
        return d[x] = cc(x/2)+cc(x/3)+cc(x/4);
}

int main()
{
    int n;
    while(scanf("%d",&n)==1)
        printf("%lld\n",cc(n));
    return 0;
}


posted @ 2013-08-18 15:48  xlc2845  阅读(120)  评论(0)    收藏  举报