#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <cmath>
#include <map>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 1e6 + 10;
const int INF = 0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false);
#define lowbit(x) ((x)&(-x))
const int mod = 1e9 + 7;
int n;
ll k;
struct mat {
ll s[105][105];
mat() {
memset(s, 0, sizeof(s));
}
inline void unit(int n) {
for (int i = 1; i <= n; i++)
s[i][i] = 1;
}
};
mat mul(mat a, mat b) {
mat c;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
c.s[i][j] = (c.s[i][j] + a.s[i][k] * b.s[k][j]) % mod;
}
}
}
return c;
}
mat mat_pow(mat k, ll b) {
mat tmp;
tmp.unit(n);
while (b) {
if (b&1)
tmp = mul(tmp, k);
k = mul(k, k);
b >>= 1;
}
return tmp;
}
int main() {
scanf("%d %lld", &n, &k);
mat ans;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
scanf("%lld", &ans.s[i][j]);
}
}
ans = mat_pow(ans, k);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
printf(j == n ? "%lld\n" : "%lld ", ans.s[i][j]);
}
}
return 0;
}
10-20
292
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-13
260
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)