題目連接:http://acm.hdu.edu.cn/showproblem.php?pid=1575php
題目:spa
1 #include <cstdio> 2 #include <cstring> 3 4 const int mod = 9973; 5 int t, n, k; 6 int a[15][15], T[15][15]; 7 8 void mul(int a[15][15], int b[15][15]) { 9 int c[15][15]; 10 memset(c, 0, sizeof(c)); 11 for(int i = 0; i < n; i++) { 12 for(int j = 0; j < n; j++) { 13 for(int k = 0; k < n; k++) { 14 c[i][j] = (c[i][j] + (long long)a[i][k] * b[k][j] % mod) % mod; 15 } 16 } 17 } 18 memcpy(a, c, sizeof(c)); 19 } 20 21 22 int main() { 23 scanf("%d", &t); 24 while(t--) { 25 scanf("%d%d", &n, &k); 26 memset(T, 0, sizeof(T)); 27 for(int i = 0; i < n; i++) { 28 T[i][i] = 1; 29 for(int j = 0; j < n; j++) { 30 scanf("%d", &a[i][j]); 31 } 32 } 33 for(; k; k >>= 1) { 34 if(k & 1) mul(T, a); 35 mul(a, a); 36 } 37 long long ans = 0; 38 for(int i = 0; i < n; i++) { 39 ans = (ans + T[i][i]) % mod; 40 } 41 printf("%lld\n", ans % mod); 42 } 43 return 0; 44 }