当前位置:网站首页>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;
}
边栏推荐
- How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic returns of BBI, MTM, obv, CCI and priceosc indicators
- How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic returns of vrsi, bbiboll, WR, bias and RSI indicators
- 今日睡眠质量记录74分
- Can GPU acceleration pytorch work?
- Traditional machine learning classification model predicts the rise and fall of stock prices
- Kotlin 协程的作用域构建器 coroutineScope与runBlocking 与supervisorScope,协程同步运行,协程挂掉的时候其他协程如何不被挂掉。
- Androi天氣
- Andersen Global通过在芬兰和丹麦的合作协议拓展北欧地区业务版图
- 牌好不好无法预料
- Three column simple Typecho theme lanstar/ Blue Star Typecho theme
猜你喜欢

Kotlin coroutine suspend function suspend keyword

Arduino controls tb6600 driver +42 stepper motor

What is pytorch? Explain the basic concepts of pytorch

Comparison of disk partition modes (MBR and GPT)

In / out / inout details of MySQL stored procedures

pytorch是什么?解释pytorch的基本概念

What is dummy change?

通过抓包下载钉钉直播回放

Quantitative investment traditional index investment decision vs Monte Carlo simulation method
![[JS component library] drag sorting component](/img/f9/4090b52da1a5784b834cb7dbbb948c.jpg)
[JS component library] drag sorting component
随机推荐
生物解锁--指纹录入流程
五篇经典好文,值得一看(2)
@Disallowcurrentexecution prevents quartz scheduled tasks from executing in parallel
市值破万亿,连续三个月销量破10万,比亚迪会成为最强国产品牌?
天津银行周传凯:从 0 到 1,我的分布式数据库落地经验谈
Canvas game 2048 free map size
Andersen Global通过在芬兰和丹麦的合作协议拓展北欧地区业务版图
[buglist] serial port programming does not read data
[North Asia server data recovery] data recovery case of Hyper-V service paralysis caused by virtual machine file loss
OceanBase 雄踞墨天轮2021年度中国数据库魔力象限领导者
[virtual machine] notes on virtual machine environment problems
五篇经典好文,值得一看
蓝桥杯单片机第七届决赛
3623. Merge two ordered arrays
Canvas random bubbling background
Aunt learning code sequel: ability to sling a large number of programmers
【服务器数据恢复】存储服务器之间迁移数据时数据丢失恢复成功案例
[virtual machine] notes on virtual machine environment problems
三栏简约typecho主题Lanstar/蓝星typecho主题
Maybe we can figure out the essence of the Internet after the dust falls