首页 > 试题广场 >

矩阵幂

[编程题]矩阵幂
  • 热度指数:16653 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
给定一个n*n的矩阵,求该矩阵的k次幂,即P^k。

输入描述:
 
第一行:两个整数n(2<=n<=10)、k(1<=k<=5),两个数字之间用一个空格隔开,含义如上所示。
接下来有n行,每行n个正整数,其中,第i行第j个整数表示矩阵中第i行第j列的矩阵元素Pij且(0<=Pij<=10)。另外,数据保证最后结果不会超过10^8。


输出描述:
对于每组测试数据,输出其结果。格式为:
n行n列个整数,每行数之间用空格隔开,注意,每行最后一个数后面不应该有多余的空格。
示例1

输入

2 2
9 8
9 3
3 3
4 8 4
9 3 0
3 5 7
5 2
4 0 3 0 1
0 0 5 8 5
8 9 8 5 3
9 6 1 7 8
7 2 5 7 3

输出

153 96
108 81
1216 1248 708
1089 927 504
1161 1151 739
47 29 41 22 16
147 103 73 116 94
162 108 153 168 126
163 67 112 158 122
152 93 93 111 97
头像 用户抉择
发表于 2021-03-29 21:45:45
#include <stdio.h> void mul(int n,int a[n][n],int b[n][n]) {     int i,j,k,c[n][n];  &nbs 展开全文
头像 渺小小螃蟹
发表于 2021-06-10 14:15:59
#include<iostream> #include<cstdio> using namespace std; struct Matrix{ int matrix[10][10]; int row,col; //行与列 Matri 展开全文
头像 在考古的小鱼干很有气魄
发表于 2023-03-17 11:02:21
#include <bits/stdc++.h> #define MAX 100 using namespace std; typedef long long ll; typedef struct matrix{ ll data[MAX][MAX]; matrix(){ me 展开全文
头像 牛客979903738号
发表于 2024-02-28 21:51:22
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = 展开全文
头像 imthewinger
发表于 2023-03-18 19:38:23
#include<iostream> using namespace std; /* * 数字快速幂,初始值为1 * 矩阵快速幂,初始值为单位矩阵 */ struct Matrix { int matrix[10][10]; int col, row; Ma 展开全文
头像 coder_bai
发表于 2023-01-12 01:27:47
#define _CRT_SECURE_NO_WARNINGS 1 #include<bits/stdc++.h> using namespace std; const int MAXN = 100; struct Matrix { int row, col; int m 展开全文
头像 Sakura0219
发表于 2024-02-08 12:28:26
#include <iostream> #include <vector> using namespace std; vector<vector<int> > multiMatrix(const vector<vector<int>& 展开全文
头像 一定要上岸的小刺猬很幸运
发表于 2023-03-17 14:25:07
#include <iostream> #include <cstdio> // 矩阵快速幂:求方阵的幂 using namespace std; struct Matrix { //定义矩阵结构体 int mtrx[10][10]; // 数组的shape应该初 展开全文
头像 土尔逊Torson
发表于 2023-05-18 23:25:41
//土尔逊Torson 编写于2023/05/18 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> using namespace std; struct Matrix { in 展开全文
头像 牛客652687585号
发表于 2022-03-07 22:16:30
#include<iostream> #include<cstdio> using namespace std; const int MAXN = 10; struct Matrix { &nbs 展开全文

问题信息

难度:
108条回答 13442浏览

热门推荐

通过挑战的用户

查看代码