Advertisement
MatveyL

123

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