【发布时间】:2015-12-23 11:44:36
【问题描述】:
我发现很难实现这个 SPOJ 问题:- http://www.spoj.com/problems/COINS/ 我找到了某人的代码,但它包含一个我希望用数组替换的映射函数。代码如下:-
#include <bits/stdc++.h>
using namespace std;
#define LL long long
map <LL,LL> ans;
LL coins(LL n)
{
if(n==0)
return 0;
else if(!ans[n]) //what does this condition check?
{
ans[n]= max(n,coins(n/2) + coins(n/3) + coins(n/4));
}
return ans[n];
}
int main() {
LL n;
while(scanf("%lld",&n)!=EOF)
{
printf("%lld\n",coins(n));
}
return 0;
}
【问题讨论】:
-
那么,问题出在哪里?我在这里看不到实际的问题...除此之外,我猜如果您使用数组,它可能无法通过所有测试...
-
如果您设法使用数组解决此问题,请告诉我...
标签: c++ arrays dynamic-programming