一下是我的 P3990 代码,已严格检查,50pts,不知道为什么。
#include<bits/stdc++.h>
using namespace std;
int n,m;
struct node{
int a[105][105];
node(){
memset(a,0,sizeof(a));
}
int *operator[](const int &x){
return a[x];
}
node operator*(node &b){
node c;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
c[i][j]=(c[i][j]+a[i][k]*b[k][j])%30011;
return c;
}
}b,d,e;
node ksm(node x,int y){
node c;
for(int i=1;i<=n;i++)
c[i][i]=1;
for(;y;y>>=1,x=x*x)
if(y&1)c=c*x;
return c;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
b[i][i]=1;
b[i+n][i]=1;
b[i][i+n]=1;
if(i!=n){
b[i+1][i]=1;
b[i][i+1]=1;
}
}
n*=2;
d=ksm(b,m-2);
e=d*b;
cout<<(e[1][n/2]-d[1][n])%30011;
}