fork(2) download
  1. #include<iostream>
  2. #include <algorithm>
  3.  
  4. int count=0,cache[50];
  5.  
  6. int f(int n)
  7. {
  8. if(n==2) count++;
  9. if(n==0 || n==1) return n;
  10. else if(cache[n]!=-1) return cache[n];
  11. else cache[n]= f(n-1)+f(n-2);
  12. return cache[n];
  13. }
  14.  
  15. int main()
  16. {
  17. std::cout << f(5);
  18. return 0;
  19. }
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
Standard output is empty