fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int fib(int n,int f[])
  5. {
  6. if(f[n]!= -1) return f[n];
  7. if( n <= 1)// 0,1asle aikne dokbe
  8. {
  9. f[n]=n;
  10. return f[n];
  11. }
  12. f[n] = fib(n-1,f)+fib(n-2,f);
  13. return f[n];
  14. }
  15.  
  16. int main()
  17. {
  18.  
  19. int n;
  20. cin >> n;
  21. int f[n+1];
  22. memset(f,-1,sizeof(f));
  23.  
  24. int ans = fib(n,f);
  25.  
  26. cout << ans << endl;
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 5328KB
stdin
5
stdout
5