#include <iostream>
#include <cstdio>
using namespace std;
int mem[200];//开记忆数组
int fib(int n)
{
  if(mem[n]!=0)
    return mem[n];  //每次先从记忆数组里寻找,如果有,直接用就行
  if(n==1||n==2)
  {
    mem[n]=1;
    return 1;
  }
  else
  {
    mem[n]=fib(n-1)+fib(n-2);
    return fib(n-1)+fib(n-2);
  }

}
int main()
{
  for(int i=1;i<=10;i++)
  cout<<fib(i)<<” “;
  return 0;
}

版权声明:本文为Hello-world-hello-lazy原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/Hello-world-hello-lazy/p/13764148.html