T3:数列

思考难度:提高?

代码难度:提高?

算法0:暴力

实际得分:0

算法1:

考虑 x = y = 1 x=y=1 x=y=1的情况,显然有 a n = a n 1 + a n 2 a_n=a_{n-1}+a_{n-2} an=an1+an2(废话),故

a n × a n + 1 a_n\times a_{n+1} an×an+1

= a n × ( a n + a n 1 ) =a_n\times (a_n+a_{n-1}) =an×(an+an1)

= a n 2 + a n 1 × a n =a_n^2+a_{n-1}\times a_n =an2+an1×an

= a n 2 + a n 1 2 + a n 2 × a n 1 =a_n^2+a_{n-1}^2+a_{n-2}\times a_{n-1} =an2+an12+an2×an1

= . . . + a 2 2 + a 1 × a 2 =...+a_2^2+a_1\times a_2 =...+a22+a1×a2

= . . . + a 2 2 + a 1 2 + a 1 × ( a 2 a 1 ) =...+a_2^2+a_1^2+a_1\times (a_2-a_1) =...+a22+a12+a1×(a2a1)

a n s = a n × a n + 1 a 1 × ( a 2 a 1 ) ans=a_n\times a_{n+1}-a_1\times (a_2-a_1) ans=an×an+1a1×(a2a1)

实际得分:20分

算法2:

注意到

a n 2 = ( x × a n 1 + y × a n 2 ) 2 a_n^2=(x\times a_{n-1}+y\times a_{n-2})^2 an2=(x×an1+y×an2)2

= x 2 × a n 1 2 + y 2 × a n 2 2 + 2 x y × a n 1 × a n 2 =x^2\times a_{n-1}^2+y^2\times a_{n-2}^2+2xy\times a_{n-1}\times a_{n-2} =x2×an12+y2×an22+2xy×an1×an2

= x 2 × a n 1 2 + y 2 × a n 2 2 + 2 x y × a n 2 × ( x × a n 2 + y × a n 3 ) =x^2\times a_{n-1}^2+y^2\times a_{n-2}^2+2xy\times a_{n-2}\times (x\times a_{n-2}+y\times a_{n-3}) =x2×an12+y2×an22+2xy×an2×(x×an2+y×an3)

= x 2 × a n 1 2 + y 2 × a n 2 2 + 2 x y × ( x × a n 2 2 + y × a n 2 × a n 3 ) =x^2\times a_{n-1}^2+y^2\times a_{n-2}^2+2xy\times (x\times a_{n-2}^2+y\times a_{n-2}\times a_{n-3}) =x2×an12+y2×an22+2xy×(x×an22+y×an2×an3)

a n 2 a_n^2 an2可以由 a n 1 2 , a n 2 2 , a n 1 × a n 2 a_{n-1}^2,a_{n-2}^2,a_{n-1}\times a_{n-2} an12,an22,an1×an2转移过来,而 a n 1 × a n 2 a_{n-1}\times a_{n-2} an1×an2可以由 a n 1 2 , a n 2 × a n 3 a_{n-1}^2,a_{n-2}\times a_{n-3} an12,an2×an3转移过来。

矩阵加速即可。

实际得分:100