#include <cstdio>#include <algorithm>#include <iostream>#include <vector>using namespace STD;typedef vector<int>Vectypedef vector<vec>MatConst intm=10007;typedef Long LongLl;mat Mul (Mat &a,mat &b) {Mat C (A.size (), VEC (b[0].size ())); for(inti =0; i < a.size (); i++) { for(intK =0; K < B.size (); k++) { for(intj =0; J < b[0].size (); j + +) {C[i][j]+=a[i][k]*b[k][j]; C[I][J]%= M; } } }returnC;} Mat Fun (Mat a,ll N) {Mat B (A.size (), VEC (A.size ())); for(inti =0; i < a.size (); i + +) {B[i][i] =1; } while(N >0){if(n&1) B=mul (b,a); A = Mul (a,a); N >>=1; }returnB;}intMain () {intTCin>> T; while(t--) {intNCin>> N; Mat A (4, VEC (4)); a[0][0]=2; a[0][1]=1; a[0][2]=1; a[0][3]=0; a[1][0]=1; a[1][1]=2; a[1][2]=0; a[1][3]=1; a[2][0]=1; a[2][1]=0; a[2][2]=2; a[2][3]=1; a[3][0]=0; a[3][1]=1; a[3][2]=1; a[3][3]=2; A = Fun (a,n);cout<< a[0][0] << Endl; }return 0;}
Dp[i][0] On behalf of I a red and green are even
Dp[i][1] represents I a red block is an odd green block is even
Dp[i][2] represents I a red block is even green block is odd
DP[I][3] On behalf of I a red and green are all odd
This state can be turned out of a matrix and then the matrix is quickly idempotent
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Poj3734blocks Matrix fast Power plus DP thought