0pts求助
查看原帖
0pts求助
801371
Midnight_szx楼主2023/4/30 11:28
#include<iostream>
#include<cmath>
#include<cstring>
#define int long long
using namespace std;
const int mod = 1000000007;
int n, k;
struct node{
	int m[105][105];
}x, y;
node operator * (const node &a, const node &b) {
	node c;
	for(int i = 1; i <= n; i++)
	    for(int j = 1; j <= n; j++)
	        c.m[i][j] = 0;
	for(int i = 1; i <= n; i++) 
	    for(int j = 1; j <= n; j++)
	        for(int k = 1; k <= n; k++)
	            c.m[i][j] = (c.m[i][i] + (a.m[i][k] % mod) * (b.m[k][j] % mod) % mod) % mod;
	return c;
}

signed main() {
	std::ios::sync_with_stdio(0);
	//freopen("P3390_1.in", "r", stdin);
	cin>>n>>k;
	for(int i = 1; i <= n; i++) 
		for(int j = 1; j <= n; j++) 
		    cin>>x.m[i][j];
	for(int i = 1; i <= n; i++)
	    y.m[i][i] = 1;
	while(k > 0) {
		if(k % 2 == 1)
		    y = y * x;
		x = x * x;
		k = k >> 1;
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++)
		    cout<<y.m[i][j]<<' ';
		cout<<'\n';
	}
	return 0;
}
2023/4/30 11:28
加载中...