Time Limits: 1000 ms Memory Limits: 65536 KB Detailed Limits
1 #include <bits/stdc++.h> 2 using namespace std; 3 int mod=2009; 4 int n,t; 5 struct pp{ 6 int m[115][115]; 7 }a; 8 int c; 9 inline pp mul(pp b,pp c) 10 { 11 pp t; 12 for(int i=1;i<=10*n;i++) 13 for(int j=1;j<=10*n;j++){ 14 t.m[i][j]=0; 15 for(int k=1;k<=10*n;k++){ 16 t.m[i][j]=(t.m[i][j]+(b.m[i][k]*c.m[k][j])%mod)%mod; 17 } 18 } 19 return t; 20 } 21 inline int fast(int x) 22 { 23 pp ans=a; 24 pp base=a; 25 while(x) 26 { 27 if(x&1)ans=mul(ans,base); 28 base=mul(base,base); 29 x=x>>1; 30 } 31 return ans.m[1][n]; 32 } 33 int main() 34 { 35 cin>>n>>t; 36 for(int i=1;i<=n;i++) 37 { 38 for(int j=1;j<=8;j++) 39 a.m[i+j*n][i+(j-1)*n]=1; 40 for(int j=1;j<=n;j++) 41 { 42 scanf("%1d",&c); 43 a.m[i][j+n*(c-1)]=1; 44 } 45 } 46 cout<<fast(t-1); 47 return 0; 48 }