当前位置:网站首页>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;
}
边栏推荐
- Today's sleep quality record 74 points
- Sequence table - find main element
- What is pytorch? Explain the basic concepts of pytorch
- Expression tree - medium order printout
- Quantitative investment traditional index investment decision vs Monte Carlo simulation method
- [buglist] serial port programming does not read data
- Kotlin 协程的作用域构建器 coroutineScope与runBlocking 与supervisorScope,协程同步运行,协程挂掉的时候其他协程如何不被挂掉。
- How many rounds of deep learning training? How many iterations?
- Common skills of quantitative investment - index part 2: detailed explanation of BOL (Bollinger line) index, its code implementation and drawing
- Kotlin 协程挂起函数 suspend 关键字
猜你喜欢

Arduino control soil moisture sensor

三栏简约typecho主题Lanstar/蓝星typecho主题

People and gods are angry. Details of Tangshan "mass beating of women incident"

With a market value of more than trillion yuan and a sales volume of more than 100000 yuan for three consecutive months, will BYD become the strongest domestic brand?
![[JS component] custom paging](/img/a7/42082c72ad8f2af1a52e1ab1293790.jpg)
[JS component] custom paging

In / out / inout details of MySQL stored procedures

高阶极点对于波形的影响

Kotlin collaboration, the life cycle of a job

什么是 dummy change?

Binary tree - right view
随机推荐
Basic operations of FreeMarker
Cards are unpredictable
单片机串口中断以及消息收发处理——对接受信息进行判断实现控制
How to determine whether T is a value type in a generic type or a reference class- How to determine whether T is a value type or reference class in generic?
Kotlin 协程的四种启动模式
Common skills for quantitative investment - drawing 3: drawing the golden section line
什么是 dummy change?
Androi weather
Et5.0 simply transform referencecollectorieditor
[JS component] browse progress bar
What is the difference between pytorch and tensorflow?
深度学习每周期的步数多少合适?
MySQL exception: com mysql. jdbc. PacketTooBigException: Packet for query is too large(4223215 > 4194304)
Rest at home today
[JS component] custom paging
. The way to prove the effect of throwing exceptions on performance in. Net core
草在结种子了
Pipeline流水线项目构建
The seventh finals of the Blue Bridge Cup
[JS component] calendar