Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- int M_S = 1002;
- vector<int>ans(M_S, -1);
- int fib(int n){
- if (ans[n]!=-1){
- return ans[n];
- }
- if (n<=2){
- ans[n]=1;
- }
- else{
- if(n%2==1){
- ans[n]=fib((n-1)/2)+fib((n-1)/2-1);
- }
- else{
- ans[n]=fib(n/2)+fib((n/2)-1);
- }
- }
- return ans[n];
- }
- int main() {
- int a;
- cin>>a;
- cout<<fib(a);
- cout<<"\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement