标签:
2 2 2 1 0 0 1 3 99999999 1 2 3 4 5 6 7 8 9
2 2686
#include<stdio.h> #include<string.h> struct matrix{ int m[11][11]; }; int n; matrix multi(matrix a,matrix b){ matrix temp; for(int i=0;i<n;++i){ for(int j=0;j<n;++j){ temp.m[i][j]=0; for(int k=0;k<n;++k) temp.m[i][j]=(temp.m[i][j]+a.m[i][k]*b.m[k][j])%9973; } } return temp; } matrix fast(matrix p,int k){ matrix ans; memset(ans.m,0,sizeof(ans.m)); for(int i=0;i<n;++i) ans.m[i][i]=1; while(k){ if(k&1) ans=multi(ans,p); p=multi(p,p); k>>=1; } return ans; } int solution(matrix a){ int ans=0; for(int i=0;i<n;++i){ ans=(ans+a.m[i][i])%9973; } return ans; } int main(){ int t,k; scanf("%d",&t); while(t--){ matrix A; scanf("%d%d",&n,&k); for(int i=0;i<n;++i){ for(int j=0;j<n;++j) scanf("%d",&A.m[i][j]); } matrix c=fast(A,k); printf("%d\n",solution(c)); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/qq_18062811/article/details/47132207