(int[][] a, int[][] b)
| 38 | // 矩阵相乘 |
| 39 | // a的列数一定要等于b的行数 |
| 40 | public static int[][] multiply(int[][] a, int[][] b) { |
| 41 | int n = a.length; |
| 42 | int m = b[0].length; |
| 43 | int k = a[0].length; |
| 44 | int[][] ans = new int[n][m]; |
| 45 | for (int i = 0; i < n; i++) { |
| 46 | for (int j = 0; j < m; j++) { |
| 47 | for (int c = 0; c < k; c++) { |
| 48 | ans[i][j] += a[i][c] * b[c][j]; |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | return ans; |
| 53 | } |
| 54 | |
| 55 | // 矩阵快速幂 |
| 56 | // 要求矩阵m是正方形矩阵 |