✔ 最佳答案
T(n) = T(n-1) + 2T(n-2) + 3 ----(1)
T(n-1) = T(n-2) + 2T(n-3) + 3 ----(2)
(1) - (2) , we have
T(n) - T(n-1) = T(n-1) + T(n-2) - 2T(n-3)
T(n) = 2T(n-1) + T(n-2) - 2T(n-3)
T(n) - 2T(n-1) - T(n-2) + 2T(n-3) = 0
Thus, the characteristic equation is,
a^3 - 2r^2 - r + 2 = 0
The roots of it is 1, -1, 2
So,
T(n) = A + B 2^n + C (-1)^n
for n = 0
0 = A + B + C ------ (1)
for n = 1
0 = A + 2B - C ------(2)
for n = 2, T(2) = 3
3 = A + 4B + C -----(3)
(3) - (1), we have B = 1
(2) - (1), we have B - 2C = 0, implies C = 1/2
So, A = -3/2
Therefore, the general solution is
T(n) = 2^n + 1/2 (-1)^n - 3/2