Advertisement
MatveyL

fibnachi

Nov 5th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5. int M_S = 45;
  6. vector<int>ans(M_S, -1);
  7. int fib(int n){
  8. if (ans[n]!=-1){
  9. return ans[n];
  10. }
  11. if (n<=1){
  12. ans[n]=1;
  13. }
  14. else{
  15. ans[n]=fib(n-1)+fib(n-2);
  16. }
  17. return ans[n];
  18. }
  19.  
  20. int main() {
  21. int a;
  22. cin>>a;
  23. cout<<fib(a-1);
  24. cout<<"\n";
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement