This competition starts...... I wrote A question and went back to bed .. there are many people with three questions in this competition .. this is a typical recursive query .. using Matrix Multiplication...
In addition, N [k] [0] indicates the number of up triangles at the k time... N [k] [1] indicates the number of down triangles at k time... so easy to use:
N [k] [0] = N [k-1] [0] * 3 + N [k-1] [1]
N [k] [1] = N [k-1] [1] * 3 + N [k-1] [0]
Because k is very large, we can only use matrix multiplication to solve the problem... to construct a matrix:
H = [3 1
1 3]
Initial Value: A = {1, 0}
So the k-day condition is required: A * h ^ k ....
Program:
[Cpp]
# Include <iostream>
# Include <algorithm>
# Include <stdio. h>
# Include <string. h>
# Include <math. h>
# Include <queue>
# Define OOS 2000000000
# Define ll long
Using namespace std;
Struct node
{
Ll s [2] [2];
} _ 2jie [70], temp;
Ll n;
Node matrix_mul (node a, node B)
{
Int k, I, j;
Memset (temp. s, 0, sizeof (temp. s ));
For (k = 0; k <2; k ++)
For (I = 0; I <2; I ++)
For (j = 0; j <2; j ++)
Temp. s [I] [j] = (temp. s [I] [j] +. s [I] [k] * B. s [k] [j]) % 1000000007;
Return temp;
}
Node getanswer (node h, ll l)
{
Ll k, I;
Node ans;
_ 2jie [1] = h;
K = 2;
For (I = 2; I <63; I ++)
{
_ 2jie [I] = matrix_mul (_ 2jie [I-1], _ 2jie [I-1]);
K * = 2;
}
Ans. s [0] [0] = 1; ans. s [0] [1] = 0;
Ans. s [1] [0] = 0; ans. s [1] [1] = 1;
While (l)
{
While (k> l)
{
I --;
K/= 2;
}
Ans = matrix_mul (ans, _ 2jie [I]);
L-= k;
}
Return ans;
}
Int main ()
{
Scanf ("% I64d", & n );
Node h;
H. s [0] [0] = 3; h. s [0] [1] = 1;
H. s [1] [0] = 1; h. s [1] [1] = 3;
H = getanswer (h, n );
Printf ("% I64d \ n", h.s [0] [0]);
Return 0;
}