LL n;
void mul(int f[7],int m[7][7])
{
int c[7]={0};
for(int i=0;i<7;i++)
for(int j=0;j<7;j++)
c[i]=(c[i]+(LL)f[j]*m[j][i])%mod;
memcpy(f,c,sizeof c);
}
void mulself(int m[7][7])
{
int c[7][7]={0};
for(int i=0;i<7;i++)
for(int j=0;j<7;j++)
for(int k=0;k<7;k++)
c[i][j]=(c[i][j]+(LL)m[i][k]*m[k][j])%mod;
memcpy(m,c,sizeof c);
}
int main()
{
int f[7]={6,5,1,4,2,3,1};
int m[7][7]={{0,1,1,0,0,0,0},
{1,0,0,1,0,0,0},
{0,0,0,0,1,0,0},
{0,0,0,0,0,1,0},
{2,3,0,0,0,0,0},
{0,2,0,0,0,0,0},
{5,3,0,0,0,0,1}};
cin>>n;
if(n == 1)
cout<<2<<endl<<3<<endl;
else if(n == 2)
cout<<1<<endl<<4<<endl;
else if(n == 3)
cout<<6<<endl<<5<<endl;
else
{
n-=3;
while(n)
{
if(n & 1) mul(f,m);
mulself(m);
n>>=1;
}
cout<<f[0]<<endl<<f[1]<<endl;
}
//system("pause");
return 0;
}
[蓝桥杯][算法提高VIP]递推求值
转载\[[F(n,1),F(n,2),F(n-1,1),F(n-1,2),F(n-2,1),F(n-2,2),1]=\\
[F(n-1,1),F(n-1,2),F(n-2,1),F(n-2,2),F(n-3,1),F(n-3,2),1]
\begin{bmatrix}
0 & 1 & 1 & 0 & 0 & 0 & 0\\
1 & 0 & 0 & 1 & 0 & 0 & 0\\
0 & 0 & 0 & 0 & 1 & 0 & 0\\
0 & 0 & 0 & 0 & 0 & 1 & 0\\
2 & 3 & 0 & 0 & 0 & 0 & 0\\
0 & 2 & 0 & 0 & 0 & 0 & 0\\
5 & 3 & 0 & 0 & 0 & 0 & 1\\
\end{bmatrix}
\\
=[F(3,1),F(3,2),F(2,1),F(2,2),F(1,1),F(1,2),1]\begin{bmatrix}
0 & 1 & 1 & 0 & 0 & 0 & 0\\
1 & 0 & 0 & 1 & 0 & 0 & 0\\
0 & 0 & 0 & 0 & 1 & 0 & 0\\
0 & 0 & 0 & 0 & 0 & 1 & 0\\
2 & 3 & 0 & 0 & 0 & 0 & 0\\
0 & 2 & 0 & 0 & 0 & 0 & 0\\
5 & 3 & 0 & 0 & 0 & 0 & 1\\
\end{bmatrix}^{n-3}
\]
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
记2023赛博杯pwn
各位师傅多批评hhh
CBCTF 个人WP -
如何提高mysql delete速度
提高mysql delete速度的方法简要介绍。
sql 数据 MySQL