http://acm.hdu.edu.cn/showproblem.php?pid=2256
题意:给定 n 求解 ?
思路: , 令 ,
那么 ,
得:
得转移矩阵:
但是上面求出来的并不是结果,并不是整数。需要加上, 由于
所以结果为
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
#define rep0(i,l,r) for(int i = (l);i < (r);i++)
#define rep1(i,l,r) for(int i = (l);i <= (r);i++)
#define rep_0(i,r,l) for(int i = (r);i > (l);i--)
#define rep_1(i,r,l) for(int i = (r);i >= (l);i--)
#define MS0(a) memset(a,0,sizeof(a))
#define MS1(a) memset(a,-1,sizeof(a))
#define MSi(a) memset(a,0x3f,sizeof(a))
#define pb push_back
#define MK make_pair
#define A first
#define B second
#define clear0 (0xFFFFFFFE)
#define inf 0x3f3f3f3f
#define eps 1e-8
#define mod 1024
#define zero(x) (((x)>0?(x):-(x))<eps)
#define bitnum(a) __builtin_popcount(a)
#define lowbit(x) (x&(-x))
#define K(x) ((x)*(x))
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
template<typename T>
void read1(T &m)
{
T x = ,f = ;char ch = getchar();
while(ch <'' || ch >''){ if(ch == '-') f = -;ch=getchar(); }
while(ch >= '' && ch <= ''){ x = x* + ch - '';ch = getchar(); }
m = x*f;
}
template<typename T>
void read2(T &a,T &b){read1(a);read1(b);}
template<typename T>
void read3(T &a,T &b,T &c){read1(a);read1(b);read1(c);}
template<typename T>
void out(T a)
{
if(a>) out(a/);
putchar(a%+'');
}
inline ll gcd(ll a,ll b){ return b == ? a: gcd(b,a%b); }
inline ll lcm(ll a,ll b){ return a/gcd(a,b)*b; }
template<class T1, class T2> inline void gmax(T1& a, T2 b){ if(a < b) a = b;}
template<class T1, class T2> inline void gmin(T1& a, T2 b){ if(a > b) a = b;} struct Matrix{
int row, col;
int m[][];
Matrix(int r,int c):row(r),col(c){ memset(m, , sizeof(m)); } bool unitMatrix(){
if(row != col) return false;
for(int i = ;i < row;i++) //方阵才有单位矩阵;
m[i][i] = ;
return true;
}
Matrix operator *(const Matrix& t){
Matrix res(row, t.col);
for(int i = ; i < row; i++)
for(int j = ;j < t.col;j++)
for(int k = ; k < col; k++)
res.m[i][j] = (res.m[i][j] + m[i][k]*t.m[k][j])% mod;
return res;
}
void print(){
for(int i = ;i < row; i++){
for(int j = ;j < col; j++)
printf("%d ",m[i][j]);
puts("");
}
}
}; Matrix pow(Matrix a, int n)
{
Matrix res(a.row, a.col);
res.unitMatrix();
while(n){
if(n & ) res = res*a;
a = a*a;
n >>= ;
}
return res;
}
int main()
{
//freopen("data.txt","r",stdin);
//freopen("out.txt","w",stdout);
Matrix mat(,);
mat.m[][] = , mat.m[][] = ;
mat.m[][] = , mat.m[][] = ;
int T, kase = ;
scanf("%d",&T);
while(T--){
int n;
read1(n);
Matrix res = pow(mat, n-);
Matrix tmp(,);
tmp.m[][] = , tmp.m[][] = ;
res = res*tmp;
printf("%d\n", (*res.m[][]-)% mod);
}
return ;
}