mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
parent
8244370d9c
commit
5ed6db9157
82
Luogu/P3390/P3390.cpp
Normal file
82
Luogu/P3390/P3390.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 105;
|
||||
const int mod = 1e9 + 7;
|
||||
|
||||
int n;
|
||||
long long k;
|
||||
|
||||
class Matrix {
|
||||
private:
|
||||
int data[N][N];
|
||||
|
||||
public:
|
||||
Matrix() {
|
||||
std::memset(data, 0x00, sizeof(data));
|
||||
}
|
||||
|
||||
int* operator[](int i) {
|
||||
return data[i];
|
||||
}
|
||||
|
||||
void build(int n) {
|
||||
for (int i = 1; i <= n; i++) {
|
||||
data[i][i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Matrix operator*(Matrix b) const {
|
||||
Matrix c;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
for (int k = 1; k <= n; k++) {
|
||||
c[i][j] = (c[i][j] + 1ll * data[i][k] * b[k][j] % mod) % mod;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
} base, ans;
|
||||
|
||||
Matrix binpow(Matrix a, long long b) {
|
||||
Matrix res;
|
||||
res.build(n);
|
||||
|
||||
while (b) {
|
||||
if (b & 1) res = res * a;
|
||||
a = a * a;
|
||||
b >>= 1;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
|
||||
cin >> n >> k;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
cin >> base[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
ans = binpow(base, k);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
cout << ans[i][j] << ' ';
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
Luogu/P3390/data/P3390_1.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3390/data/P3390_1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3390/data/P3390_1.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3390/data/P3390_1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user