博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
51Nod 1113 矩阵快速幂
阅读量:4657 次
发布时间:2019-06-09

本文共 1501 字,大约阅读时间需要 5 分钟。

1 #include 
2 #include
3 #include
4 #include
5 using namespace std; 6 7 typedef long long ll; 8 int n, m; 9 const int maxn = 105;10 const int MOD = 1e9 + 7;11 12 struct node{13 ll a[maxn][maxn];14 };15 16 node A, ans;17 18 node multi(node x, node y){19 node z;20 for(int i = 1;i <= n;i++){21 for(int j = 1;j <= n;j++){22 z.a[i][j] = 0;23 for(int k = 1;k <= n;k++){24 z.a[i][j] += x.a[i][k]*y.a[k][j]%MOD;25 z.a[i][j] %= MOD;26 }27 }28 }29 return z;30 }31 32 void f(){33 while(m > 0){34 if(m%2){35 //ans = ans*a%MOD;36 ans = multi(ans, A);37 }38 //a = (a*a)%MOD;39 A = multi(A,A);40 m /= 2;41 }42 }43 44 int main(){45 ios_base::sync_with_stdio(false);46 cin.tie(0);47 cin >> n >> m;48 for(int i = 1;i <= n;i++){49 for(int j = 1;j <= n;j++){50 cin >> A.a[i][j];51 ans.a[i][j] = A.a[i][j];52 }53 }54 m--;55 f();56 for(int i = 1;i <= n;i++){57 for(int j = 1;j<=n;j++)58 {59 if(j == 1){60 cout << ans.a[i][j];61 }62 else{63 cout << " " << ans.a[i][j];64 }65 }66 cout << endl;67 }68 return 0;69 }

 

转载于:https://www.cnblogs.com/ouyang_wsgwz/p/9037682.html

你可能感兴趣的文章
Solution for Concurrent number of AOS' for this application exceeds the licensed number
查看>>
CSE 3100 Systems Programming
查看>>
IntelliJ IDEA 的Project structure说明
查看>>
Java Security(JCE基本概念)
查看>>
Linux Supervisor的安装与使用入门
查看>>
创建 PSO
查看>>
JasperReport报表设计4
查看>>
项目活动定义 概述
查看>>
团队冲刺04
查看>>
我的Python分析成长之路8
查看>>
泛型在三层中的应用
查看>>
SharePoint2010 -- 管理配置文件同步
查看>>
.Net MVC3中取得当前区域的名字(Area name)
查看>>
获得屏幕像素以及像素密度
查看>>
int与string转换
查看>>
adb命令 判断锁屏
查看>>
推荐一个MacOS苹果电脑系统解压缩软件
查看>>
1035等差数列末项计算
查看>>
CDMA鉴权
查看>>
ASP.NET MVC Identity 兩個多個連接字符串問題解決一例
查看>>