标签:
#include <iostream> #include <cstdio> #include <cstring> #define REP(i, s, n) for(int i = s; i <= n; i ++) #define REP_(i, s, n) for(int i = n; i >= s; i --) #define MAX_N 10 + 5 #define mod 9973 using namespace std; int n, k; struct node{ int Mtx[MAX_N][MAX_N]; }a; node operator+(node a, node b){ node c; REP(i, 1, n) REP(j, 1, n){ c.Mtx[i][j] = (a.Mtx[i][j] + b.Mtx[i][j]) % mod; } return c; } node operator*(node a, node b){ node c; REP(i, 1, n) REP(j, 1, n){ c.Mtx[i][j] = 0; REP(k, 1, n) c.Mtx[i][j] = (a.Mtx[i][k] * b.Mtx[k][j] + c.Mtx[i][j]) % mod; } return c; } node operator^(node a, int k){ if(k == 0){ REP(i, 1, n) REP(j, 1, n) a.Mtx[i][j] = 1; return a; } if(k == 1) return a; node res = a ^ (k >> 1); if(k & 1) return res * res * a; else return res * res; } int main(){ int T; scanf("%d", &T); while(T --){ scanf("%d%d", &n, &k); REP(i, 1, n) REP(j, 1, n) scanf("%d", &a.Mtx[i][j]); a = a ^ k; int ans = 0; REP(i, 1, n) ans = (ans + a.Mtx[i][i]) % mod; printf("%d\n", ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/ALXPCUN/p/4587753.html