c++ 递归斐波那契算法及时间复杂度

#include<iostream>

int fib(int n){
    if(n<2)
        return n;
    else
        return fib(n-1) + fib(n-2);
}

int main(){
    for(int i=0;i<10;i++){
        std::cout << fib(i) << std::endl;
    }

    return 0;
}

时间复杂度为 O(2ⁿ);

原文地址:https://www.cnblogs.com/zychengzhiit1/p/5772615.html