#include <iostream>
#include <vector>
using namespace std;
typedef long long int intLong;
class Fib{
public:
vector<intLong> v;
Fib() {v.push_back(0);v.push_back(1);}
intLong operator() (intLong n)
{
if (v.size() > n)
return v[n];
v.push_back((*this)(n - 2) + (*this)(n - 1));
return v[n];
}
};
int main()
{
Fib f;
cout<<"Result : " << f(90) <<endl;
for (int j = 0;j < f.v.size() ;)
{
cout << j++ << " : " << f.v[j] <<endl;
}
}
c++ 函数对象动态规划解斐波那契数列
最新推荐文章于 2022-03-05 15:41:16 发布