... HAVE U TRIED .... AT LEAST 3 TIMES ... OK U CAN SEE THIS ...

Tuesday, December 24, 2013

UVA-12459 :: Bees' ancestors

#include <iostream>
#include <bits/stdc++.h>
using namespace std ;

long long int dp[85] ;
long long int func (int x)
{
    if (x==0) return 1 ;
    if (x==1) return 1 ;
    if (dp[x] != -1) return dp[x] ;
    else  dp[x]=1 ;

    return dp[x]= (func(x-1)+func(x-2)) ;
}

int main ()
{
    long long  int p ,x ;
    memset(dp,-1,sizeof (dp)) ;

    while (cin>>p && p!=0)
    {
        x=func(p) ;
        cout<<x<<endl ;
    }

    return 0 ;
}