回复 17楼 laoyang103
f(n) = 2 * f(n - 1) + 3 * f(n - 2)
f(n) + f(n - 1) = 3 * (f(n - 1) + f(n - 2))
= 3 * 3 *(f(n - 2) + f(n - 3))
= 3^(n - 1) * (f(1) + f(0))
= 2 * 3^(n - 1)
f(n) = 2 * 3^(n - 1) - f(n - 1)
= 2 * 3^(n - 1) - 2 * 3^(n - 2) + f(n - 2)
= 2 * 3^(n - 1) - 2 * 3^(n - 2) + 2 * 3^(n - 3) - f(n - 3)
...
= 2 * [3^(n-1) - 3^(n-2) + 3^(n-3) ... +(-1)^(n-2) * 3] + (-1)^(n-1) * f(1)
中括号中的部分是一个等比数列前若干项的和
其中
a1 = 3^(n-1)
q = -1/3
项数为n-1项。
代入公式后为
f(n) = 2 * 3^(n-1) * (1 - (-1/3)^(n-1)) / (1 + 1/3) + (-1)^(n-1)
化简后即
f(n) = (3^n + (-1)^n)/2