First, we will introduce the idea of solving this question: classification. Be good at abstracting familiar models from complicated problems to solve them. Bytes. At the beginning, I listed the recurrence relationship of this question based on the idea of the poj monthly contest solution report and wrote the program myself. I found it very troublesome and submitted a timeout warning to me! In desperation, I can only look for other methods. I thought for a long time that there was no good progress. Finally, under the guidance of my senior brother, I referred to the above problem-solving report, this paper simplifies the recursive formula by using the properties of famous Fibonacci identities. // 4*(2 * F (n-1) ^ 2 + (-1) ^ (n-1) ^ 2 // n points odd or even discussed, but the running result is still incorrect. After debugging for a long time, there is no good result, after several hours of suffering, I accidentally changed short to int and found that the result was normal. It turned out to be a cross-border disaster! The submission was successful, more than 8000 ms. It is clear that such a program is difficult to pass during the general competition, so I started to improve the multi-precision algorithm. Indeed, the running time has been greatly improved. On the basis of the original 10-digit system, I used a 1000-digit system, reducing the program running time to more than 1000 ms. Indeed, the power of algorithms is infinite! Note that the first one uses printf ("% d") and later must use printf ("% 03d"). errors are prevented here. The following section describes the improvement of my high-precision algorithm: const int M = 1000;/high-precision Multiplication
Void mult (int * a, int * B, int * C)
{// C = A * B;
Int I, j, M, N, K;
M = A [0]; n = B [0];
K = N + m-1;
For (I = 0; I <= K; I ++) C [I] = 0;
For (I = 1; I <= m; I ++ ){
If (A [I]) for (j = 1; j <= N; j ++) if (B [J]) c [I + J-1] + = A [I] * B [J];
}
For (I = K; I> = 1; I --) if (C [I]> = m) {C [I-1] + = C [I]/m; c [I] % = m ;}////////////////
If (C [0]> 0)
{K ++; for (I = K; I> = 1; I --) C [I] = C [I-1];} C [0] = K;
} // High-precision addition void add (int * a, int * B, int * C)
{// C = A + B;
Int m, n, I, J, K;
M = A [0]; n = B [0];
If (M <n) k = N; else K = m;
For (I = 0; I <= K; I ++) C [I] = 0;
J = K;
For (I = N; I> = 1; I --, j --) C [J] = B [I];
J = K;
For (I = m; I> = 1; I --, j --) C [J] + = A [I];
For (I = K; I> = 1; I --)
{If (C [I]> = m) {C [I-1] ++; C [I]-= m ;} //////////////////////////////////
}
If (C [0])
{K ++; for (I = K; I> = 1; I --) C [I] = C [I-1];}
C [0] = K;
}