Base time limit: 3Second space limit: 131072 KB score: gives a matrix of n * n, where the elements are positive integers. The M-Order of the matrix is obtained. Because the M-time calculation results are too large, only the results of each mod (10^9 + 7) need to be output. Input
Line 1th: 2 numbers n and m, separated by a space in the middle. n is the size of the matrix, M is the M-th square. (2 <= n <=, 1 <= M <= 10^9) 2-n + 1 rows: N number per row, corresponding to 1 rows in the n * n Matrix. (0 <= N[i] <= 10^9)
Output
Total n rows, number of n per row, corresponding to the results of M-time mod (10^9 + 7).
Input example
2 31 11 1
Output example
4 44 4
Learn the matrix multiplication
#include <cstdio>#include<cstdlib>#include<iostream>using namespaceStd;typedefLong LongLL;Const intmod=1e9+7; typedefstruct{ intm[111][111];} Matrix;intN,k;matrixoperator*(Matrix A,matrix b) {matrix res; LL x; for(intI=0; i<n;i++) { for(intj=0; j<n;j++) {x=0; for(intk=0; k<n;k++) {x= (x+ (LL) a.m[i][k]*b.m[k][j])%MOD; } Res.m[i][j]=x%MOD; } } returnRes;} Matrix Fast_cover (Matrix A,intk) {matrix S; for(intI=0;i<111; i++) s.m[i][i]=1;//Unit Matrix while(k) {if(k&1) s=s*A; A=a*A; K>>=1; } returns;}intMain () { while(SCANF ("%d%d", &n,&k)! =EOF) {Matrix A; for(intI=0; i<n;i++) { for(intj=0; j<n;j++) {scanf ("%d",&A.m[i][j]); }} a=Fast_cover (a,k); for(intI=0; i<n;i++) { for(intj=0; j<n-1; j + +) printf ("%d", A.m[i][j]); printf ("%d\n", a.m[i][n-1]); } } return 0;}
NOD 1113 Matrix Fast Power