Basic exercise Matrix multiplicationtime limit: 1.0s memory limit: 512.0MBProblem description given an n-order matrix A, the M power of output A (m non-negative integer)
For example:
A =
1 2
3 4
A power of 2 times
7 10
15 22 input Format the first line is a positive integer N, M (1<=n<=30, 0<=m<=5), representing the order of the matrix A and the required power number
Next n rows, each row n absolute value does not exceed 10 non-negative integer, the output format of the description matrix A outputs a total of n rows, n integers per row, representing the matrix corresponding to the M power of a. Separate sample input with a space between adjacent numbers 2 2
1 2
3 4 Sample Output 7 10
15 22
ImportJava.util.Scanner; Public classMain { Public Static voidMain (string[] args) {//TODO auto-generated Method Stub inta[][]=New int[30] [30]; intb[][]=New int[30] [30]; intc[][]=New int[30] [30]; intI,j,k,l,m,n; Scanner SC=NewScanner (system.in); N=Sc.nextint (); M=Sc.nextint (); for(i=0;i<n;i++) for(j=0;j<n;j++) A[i][j]=Sc.nextint (); for(i=0;i<n;i++) B[i][i]=1; for(i=0;i<m;i++){ for(j=0;j<n;j++){ for(k=0;k<n;k++) {C[j][k]=0; for(l=0;l<n;l++) C[j][k]+=a[j][l]*B[l][k]; } } for(j=0;j<n;j++) for(k=0;k<n;k++) B[j][k]=C[j][k]; } for(i=0;i<n;i++){ for(j=0;j<n;j++) System.out.print (B[i][j]+" "); System.out.println (); } }}
Basic Exercise Matrix multiplication