题目: |
#include <iostream>
#include <cstring>
using namespace std;
int n;
int a[101];
int f(int n)
{
int tmp;
if(a[n-1]>0) tmp=a[n-1];
else tmp=f(n-1);
if (a[n-2]>0) tmp += a[n-2];
else tmp += f(n-2);
a[n]=tmp;
return tmp;
}
int main()
{
memset(a,0,sizeof(a));
a[1]=2;
a[2]=3;
cout<<f(9)<<endl;
return 0;
} 输出:89
|