当前位置:网站首页>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;
}
边栏推荐
- Jenkins持续集成操作
- Aof persistence
- Common skills for quantitative investment - drawing 2: drawing the moving average
- Hard (magnetic) disk (II)
- STM32 USB Basics
- Can GPU acceleration pytorch work?
- Common skills for quantitative investment - drawing 3: drawing the golden section line
- 五篇经典好文,值得一看(2)
- The grass is bearing seeds
- Deep learning model pruning
猜你喜欢

深度学习训练多少轮?迭代多少次?

(01).NET MAUI实战 建项目

Today's sleep quality record 74 points

Antdpro - protable realizes the linkage effect of two selection boxes

Unity calls alertdialog

MySQL locates the position of the character in the string String substitution

Win10 home vs pro vs enterprise vs enterprise LTSC

408 true question - division sequence

Common skills for quantitative investment - drawing 3: drawing the golden section line
![[JS component] floating text](/img/e5/7faad5422bba919bed34e3dbcf7ba0.jpg)
[JS component] floating text
随机推荐
MySQL lpad() and rpad() concatenate string functions with specified length
Binary tree -- using hierarchical sequence and middle sequence to determine a tree
STM32 USB Basics
Comparison of disk partition modes (MBR and GPT)
How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic returns of BBI, MTM, obv, CCI and priceosc indicators
通过抓包下载钉钉直播回放
Et5.0 simply transform referencecollectorieditor
Quantitative investment traditional index investment decision vs Monte Carlo simulation method
[JS component] create a custom horizontal and vertical scroll bar following the steam style
pytorch和tensorflow有什么区别?
Druid reports an error connection holder is null
Arduino interrupt
Pipeline pipeline project construction
草在结种子了
三角波与三角波卷积
Composite key relationships using Sqlalchemy - relationships on composite keys using Sqlalchemy
Androi天气
. The way to prove the effect of throwing exceptions on performance in. Net core
Common skills of quantitative investment -- Drawing Part 1: Drawing stock closing price curve and ochl candle chart
Arduino uses esp8266+ lighting technology + Xiaoai audio to realize voice control switch