小编Mon*_*San的帖子

条件递归

以下是来自spoj的问题的实现: - http://www.spoj.com/problems/COINS/

#include <stdio.h>

#define ll long long

ll arr[100000];

ll max(ll n)
{
    if(n < 49999)// Doubt
    {
        if(!arr[n])
            return arr[n] = max(n/2) + max(n/3) + max(n/4);
        else
            return arr[n];
    }
    else
        return max(n/2) + max(n/4) + max(n/3);
}


int main()
{
    ll n, c = 0, i;

    for(i = 0; i < 12; i++) // Also why 12 when the input can be <12
    {
        arr[i] = i;
    }

    while(scanf("%lld", &n) != EOF)
    {
        printf("%lld\n", max(n));

    } …
Run Code Online (Sandbox Code Playgroud)

c if-statement dynamic-programming conditional-statements

6
推荐指数
1
解决办法
160
查看次数