#include <cstring>
#include <iostream>
using namespace std;
int main(int argc, char **argv) {
int n, m;
int a[100][100];
int re[100][100];
int b[100][100];
memset(re, sizeof(re), 0);
cin >> n >> m;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) {
cin >> a[i][j];
b[i][j] = a[i][j];
}
m--;
while (m--) {
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) {
int t = 0;
while (t < n) {
cout << "b[i][t]:" << b[i][t] << "a[t][j]:" << a[t][j] << endl;
re[i][j] += b[i][t] * a[t][j];
t++;
}
}
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) {
b[i][j] = re[i][j];
re[i][j] = 0;
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j)
cout << b[i][j] << endl;
}
return 0;
}
蓝桥杯 矩阵的幂
最新推荐文章于 2024-03-30 21:58:04 发布