[Problem]
同学们在做题时常遇到这种函数
f(x)=5 (x>=0)
f(x)=f(x+1)+f(x+2)+1 (x<0)
下面就以这个函数为题做一个递归程序吧
[Solution]
#include <iostream> using namespace std;int array[31];int main(){int n;while(cin >> n){if(n >= 0){cout << 5 << endl;}else{array[0] = 5;array[1] = 11;n = -n;for(int i = 2; i <= n; ++i){array[i] = array[i-1] + array[i-2] + 1;}cout << array[n] << endl;}}return 0; }