m,n=map(int,input().split()) #m阶矩阵 幂为n if n==0: l = [[0] * m for i in range(m)] for i in range(m): l[i][i]=1 for i in range(m): for j in range(m): print(l[i][j],end=" ") print() else: l1=[] l2=[] a=0 for i in range(m): l1.append(input().split()) l=[[0]*m for i in range(m)] l3=[[0]*m for i in range(m)] for i in range(m): for j in range(m): l[i][j]=int(l1[i][j]) l3[i][j] = int(l1[i][j]) for i in range(n-1): for p in range(m): for q in range(m): for o in range(m): a=a+l[p][o]*l3[o][q] l2.append(a) a=0 t=0 for e in range(m): for r in range(m): l[e][r] = l2[t] t+=1 l2=[] for i in range(m): for j in range(m): print(l[i][j],end=" ") print()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)