-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlg-P3390.cpp
57 lines (47 loc) · 1.12 KB
/
lg-P3390.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAX_N = 101;
long long n, k;
struct Matrix {
long long map[MAX_N][MAX_N];
Matrix operator*(const Matrix &m) const {
Matrix r = {};
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int l = 0; l < n; l++) {
r.map[i][j] += (map[i][l] * m.map[l][j]) % MOD;
r.map[i][j] %= MOD;
}
}
}
return r;
}
} a, ans;
void quick_pow(long long x);
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a.map[i][j];
}
ans.map[i][i] = 1;
}
quick_pow(k);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << ans.map[i][j] << " ";
}
cout << endl;
}
return 0;
}
void quick_pow(long long x) {
do {
if (x & 1) {
ans = ans * a;
}
a = a * a;
x >>= 1;
} while (x);
}