注意事项: 恶补一波线性代数,矩阵的零次幂竟然是单位矩阵,太伤心了┭┮﹏┭┮
#include<iostream> #include<algorithm> #include<cmath> #include<string> #include<cstring> using namespace std; int a[1001][1001]; int b[1001][1001]; int c[1001][1001]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> a[i][j]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) b[i][j] = a[i][j]; if (m == 0) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { if (i == j) a[i][j] = 1; else a[i][j] = 0; } } else { for (int i = 1; i < m; i++) { memset(c, 0, sizeof(c)); for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { for (int l = 0; l < n; l++) { c[j][k] += a[j][l] * b[l][k]; } } } for (int j = 0; j < n; j++) for (int k = 0; k < n; k++) a[j][k] = c[j][k]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << a[i][j]; if (j != n) cout << " "; } cout << endl; } return 0; }
0.0分
0 人评分
C语言训练-求s=a+aa+aaa+aaaa+aa...a的值 (C语言代码)浏览:663 |
这可能是一个假的冒泡法浏览:1071 |
最小公倍数 (C语言代码)浏览:894 |
输出正反三角形 (C语言代码)浏览:859 |
WU-蓝桥杯算法提高VIP-企业奖金发放 (C++代码)浏览:1266 |
WU-格式化数据输出 (C语言代码)浏览:1818 |
IP判断 (C语言描述,蓝桥杯)浏览:1118 |
关于C语言变量位置的问题浏览:294 |
简单的a+b (C语言代码)浏览:572 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:756 |