Transferred from a ox.
Fibonacci Series: F (0) = 1, F (1) = 1, F (n) = f (n-1) + f (n-2)
The method we used to quickly calculate the nth entry of the Fibonacci series is to construct a constant coefficient matrix.
(1) Fibonacci Series F [N] = f [n-1] + F [N-2], f [1] = f [2] = the nth quick method of 1 (high precision is not considered)
Solution:
Consider the matrix of 1 × 2 [f [N-2], F [n-1]. Based on the recurrence relationship of the Fibonacci series, we can multiply by a 2 × 2 matrix A to obtain the matrix: [f [n-1], F [N].
That is: [f [N-2], F [n-1] * A = [f [n-1], F [N] = [f [n-1], f [n-1] + F [N-2]
It is easy to construct this 2x2 matrix A, that is:
0 1
1 1
Therefore, [f [1], F [2] × A = [f [2], F [3]
Because matrix multiplication satisfies the combination Law, there are:
[F [1], F [2] × a ^ (n-1) = [f [N], F [n + 1]
F [N] is the first element of this matrix.
(2) Series F [N] = f [n-1] + F [N-2] + 1, f [1] = f [2] = fast method for the nth item of 1 (high precision is not considered)
Solution:
Considering the matrix [f [N-2], F [n-1], 1] of 1 × 3, we hope to obtain a matrix A of 3 × 3, multiply the matrix of 1 × 3 by a to obtain the matrix: [f [n-1], F [N], 1]
That is: [f [N-2], F [n-1], 1] * A = [f [n-1], F [N], 1] = [f [n-1], f [n-1] + F [N-2] +]
It is easy to construct the 3x3 matrix A, namely:
0 1 0
1 1 0
0 1 1
Therefore, [f [1], F [2], 1] * a ^ (n-1) = [f [N], F [n + 1], 1]
(3) Series F [N] = f [n-1] + F [N-2] + n + 1, f [1] = f [2] = fast method for the nth entry of 1 (high accuracy is not considered ).
Solution:
Considering the matrix [f [N-2], F [n-1], n, 1] of 1 × 4, we hope to obtain a 4 × 4 matrix, multiply the matrix of 1 × 4 by a to obtain the matrix: [f [n-1], F [N], n +]
That is: [f [N-2], F [n-1], n, 1] * A = [f [n-1], F [N], N +] = [f [n-1], F [n-1] + F [N-2] + n + 1, N +]
It is easy to construct the 4x4 matrix A, namely:
0 1 0 0
1 1 0 0
0 1 1 0
0 1 1 1
Therefore, [f [1], F [2],] * a ^ (n-1) = [f [N], F [n + 1], n +]
(4) Series F [N] = f [n-1] + F [N-2], f [1] = f [2] = the first n items of 1 and S [N] = f [1] + F [2] + ...... + Fast method for F [N] (high accuracy is not considered ).
Solution:
Considering the matrix of 1x3 [f [N-2], F [n-1], s [N-2], we hope to multiply by a 3x3 matrix, obtain a matrix of 1 × 3: [f [n-1], F [N], s [n-1]
That is: [f [N-2], F [n-1], s [N-2] * A = [f [n-1], F [N], s [n-1] = [f [n-1], F [n-1] + F [N-2], s [N-2] + F [n-1]
It is easy to obtain that matrix A of 3x3 is:
0 1 0
1 1 1
0 0 1
The matrix scale of this method is (R + 1) * (R + 1)
F (1) = F (2) = S (1) = 1, so there are
[F (1), F (2), S (1)] * A = [F (2), F (3), S (2 )]
Therefore: [F (1), F (2), S (1)] * a ^ (n-1) = [F (N), F (n + 1 ), S (n )]
(5) Series F [N] = f [n-1] + F [N-2] + n + 1, f [1] = f [2] = the first n items of 1 and S [N] = f [1] + F [2] + ...... + Fast method for F [N] (high accuracy is not considered ).
Solution:
Consider the matrix of 1 × 5 [f [N-2], F [n-1], s [N-2], n, 1 ],
We need to find a 5 × 5 matrix A and multiply it by a to obtain the following 1 × 5 matrix [f [n-1], F [N], s [n-1], n + 1, 1]
That is: [f [N-2], F [n-1], s [N-2], n, 1] * A = [f [n-1], F [N], s [n-1], n + 1, 1]
= [F [n-1], F [n-1] + F [N-2] + n + 1, s [N-2] + F [n-1], n +]
It is easy to construct a as follows:
0 1 0 0 0
1 1 1 0 0
0 0 1 0 0
0 1 0 1 0
0 1 0 1 1
Therefore: [F (1), F (2), S (1), 3, 1] * a ^ (n-1) = [F (N), F (n + 1 ), S (n), N + 2, 1]
Generally, if f [N] = p * f [n-1] + Q * f [N-2] + R * n + S
You can construct a matrix:
0 Q 0 0 0
1 p 1 0 0
0 0 1 0 0
0 r 0 1 0
0 s 0 1 1
More generally, for f [N] = sigma (A [n-I] * f [n-I]) + poly (N ), where 0 <I <= a constant C, poly (N) represents the polynomial of N, and we can still construct a similar matrix A to solve the problem.
Set degree (poly (N) = D, and specify d =-1 when poly (N) = 0. At this time, it corresponds to linear homogeneous recurrence of constant coefficients. The complexity of the First n operators in this method is as follows:
(C + 1) + (D + 1) 3 * logns
For example, a (0) = 1, A (1) = 1, a (n) = x * a (n-1) + y * a (n-2) (N> = 2); given three values n, x, and Y, evaluate S (n): S (n) = a (0) 2 + a (1) 2 + ...... + A (n) 2.
Solution:
Consider the matrix of 1*4 [s [N-2], a [n-1] ^ 2, a [N-2] ^ 2, a [n-1] * A [N-2]
We need to find a 4 × 4 matrix A so that it multiplied by a to obtain a matrix of 1 × 4.
[S [n-1], a [n] ^ 2, a [n-1] ^ 2, a [n] * A [n-1]
That is: [s [N-2], a [n-1] ^ 2, a [N-2] ^ 2, A [n-1] * A [N-2] * A = [s [n-1], a [n] ^ 2, a [n-1] ^ 2, A [n] * A [n-1]
= [S [N-2] + A [n-1] ^ 2, x ^ 2 * A [n-1] ^ 2 + y ^ 2 * A [N-2] ^ 2 + 2 * x * y * A [n-1] * A [N-2],
A [n-1] ^ 2, x * A [n-1] ^ 2 + y * A [N-2] a [n-1]
You can construct a matrix:
1 0 0 0
1 x ^ 2 1 x
0 y ^ 2 0 0
0 2xy 0 y
Therefore: [s [0], a [1] ^ 2, a [0] ^ 2, a [1] * A [0] * a ^ (n-1) = [s [n-1], a [n] ^ 2, a [n-1] ^ 2, a [n] * A [n-1]
Therefore, [s [0], a [1] ^ 2, a [0] ^ 2, a [1] * A [0] * a ^ (N) = [s [N], a [n + 1] ^ 2, a [n] ^ 2, a [n + 1] * A [n]
If a = (B * C), at = (B * C) t = CT * BT
Hence
This example is HDU 3306.
Construct a matrix to solve the series recurrence Problem