среда, 20 февраля 2008 г.

Project Euler, problem 117

What I really like about "Project Euler" competition is - sometimes problems that looks very hard have very easy solution. Actually they may be solved using "p&p" (paper and pencil)programing language.

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];

}

Комментариев нет: