当前位置:网站首页>Matrix fast power
Matrix fast power
2022-06-13 00:56:00 【-LM-】

- Initialize the cell matrix
- Enter the matrix value
- Similar to fast power matrix multiplication
- Overloaded operation *, Used to represent matrix multiplication
#include<bits/stdc++.h>
using namespace std;
const int maxn=110;
const int mod=1e9+7;
struct mat{
int m[maxn][maxn];
}unit;
int n;
void init_unit()
{
for(int i=0;i<maxn;i++)
unit.m[i][i]=1;
return ;
}
mat operator *(mat a,mat b)
{
mat ret;
long long x;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
x=0;
for(int k=0;k<n;k++)
x=(x%mod+((long long)a.m[i][k]*b.m[k][j])%mod)%mod;
ret.m[i][j]=x%mod;
}
}
return ret;
}
mat pow_mat(mat a,long long y)
{
mat res=unit;
while(y)
{
if(y&1) res=res*a;
y>>=1;
a=a*a;
}
return res;
}
int main()
{
long long x;
init_unit();
while(cin>>n>>x)
{
mat a;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>a.m[i][j];
a=pow_mat(a,x);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(j+1==n) cout<<a.m[i][j]<<endl;
else cout<<a.m[i][j]<<" ";
}
return 0;
}
边栏推荐
- (01). Net Maui actual construction project
- Triangle wave and triangle wave convolution
- Get preview of precast body
- Common skills for quantitative investment - drawing 3: drawing the golden section line
- Expression tree - medium order printout
- 阿姨学代码续集:能力吊打大批程序员
- Canvas random bubbling background
- What is dummy change?
- 深度学习每周期的步数多少合适?
- Notes: the 11th and 12th generation mobile versions of Intel support the native thunderbolt4 interface, but the desktop version does not
猜你喜欢

牌好不好无法预料

.net core 抛异常对性能影响的求证之路

Comparison of disk partition modes (MBR and GPT)

Introduction to ROS from introduction to mastery (zero) tutorial

Hard (magnetic) disk (I)

Self use notes for problem brushing learning

Download nail live playback through packet capturing

Common skills for quantitative investment - indicators Chapter 3: detailed explanation of RSI indicators, their code implementation and drawing

【SCA-CNN 解读】空间与通道注意力:Spatial and Channel-wise Attention

How many steps are appropriate for each cycle of deep learning?
随机推荐
Illustrator tutorial, how to add dashes and arrows in illustrator?
MySQL lpad() and rpad() concatenate string functions with specified length
【SCA-CNN 解读】空间与通道注意力:Spatial and Channel-wise Attention
Comparison of disk partition modes (MBR and GPT)
ROS2之OpenCV人脸识别foxy~galactic~humble
[JS] solve the problem that removeeventlistener is invalid after the class listening event from new is bound to this
Opencv face recognition of ros2 foxy~galactic~humble
MySQL locates the position of the character in the string String substitution
Lessons learned from the NLP part of the course "Baidu architects hands-on deep learning"
The grass is bearing seeds
How the ET framework uses it to develop games
[sca-cnn interpretation] spatial and channel wise attention
Bubble sort - alternate sort at both ends
[JS] battle chess
Et5.0 simply transform referencecollectorieditor
Basic operations of FreeMarker
今日睡眠质量记录74分
[JS component] create a custom horizontal and vertical scroll bar following the steam style
也许尘埃落地,我们才能想清楚互联网的本质
ImportError: cannot import name &#039; get_ ora_ doc&#039; from partially initialized module