标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3667 Accepted Submission(s): 2733
#include<iostream> #include<cstring> using namespace std; class M{ public : int m[10][10]; }; int n; M multi(M a, M b){ M t; for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j){ t.m[i][j] = 0; for(int k = 0; k < n; ++k) t.m[i][j] = (t.m[i][j] + a.m[i][k] * b.m[k][j]) % 9973; } } return t; } M base,ans; void init(){ memset(ans.m,0,sizeof(ans.m)); for(int i=0;i<n;i++){ ans.m[i][i]=1; } } int main(){ int t;cin>>t; long long int k=0; while(t--){ cin>>n>>k; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>base.m[i][j]; } } init(); while(k){ if(k & 1){ ans = multi(ans, base); } base = multi(base, base); k >>= 1; } int aw=0; for(int i=0;i<n;i++){ aw+=ans.m[i][i]; aw=aw%9973; } cout<<aw<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/demodemo/p/4748986.html