#include<iostream>
using namespace std;
int foo(int n) {if (n < 1)return n;return (foo(n - 1) + foo(n - 2));
}
int main() {printf("%d\n", foo(5));return 0;
}
解析:
foo(5)=foo(4)+f00(3)=foo(3)+foo(2)+foo(3)=2foo(3)+foo(2)=2(foo(2)+foo(1))+foo(2)=3foo(2)+2foo(1)=3(foo(1)+foo(0))+2foo(1)
=5foo(1)+3foo(0)=5(foo(0)+foo(-1))+3foo(0)=8foo(0)+5foo(-1)=-5