【发布时间】:2016-03-31 12:09:37
【问题描述】:
以下是来自 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));
}
return 0;
}
为什么if条件包含n
【问题讨论】:
-
@SouravGhosh 为什么是 49999?
-
我建议您取 50000 并手动计算出您的阵列中会发生什么。
-
49999 似乎没有理论上的理由。它也可能是 99999。
-
我认为制作程序的人广泛使用了像
gdb这样的调试器,然后硬编码了那些神奇的值或限制(不管你想怎么称呼它):\ -
为什么要用
#define ll long long语句来隐藏代码?代码应该写得尽可能清楚。代码中ll的实例没有写清楚代码
标签: c if-statement conditional-statements dynamic-programming