Problem 117 looks beautiful. Its very easy to make complex recursive solution and a bit harder to think and make very simple solution without any recursion.
Here is mine:
LONGLONG euler_117()
{
map<int,LONGLONG> _set;
_set[0]=1;_set[1]=1;_set[2]=2;_set[3]=4;
for(int i=4;i<=50;++i)
_set[i]=_set[i-1]+_set[i-2]+_set[i-3]+_set[i-4];
return _set[50];
}
Комментариев нет:
Отправить комментарий