码迷,mamicode.com
首页 > 其他好文 > 详细

矩阵快速幂模板

时间:2015-07-31 14:30:59      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

 1 struct Matrix {
 2         int n , m ;
 3         int mat[M][M] ;
 4         int * operator [] (int x) {
 5                 return mat[x] ;
 6         }
 7 }
 8 
 9 Matrix mul (Matrix x , Matrix y) {
10         Matrix res ;
11         memset (res.mat , 0 , sizeof(res.mat)) ;
12         res.n = x.n , res.m = y.m ;
13         for (int i = 0 ; i < x.n ; i ++) {
14                 for (int j = 0 ; j < y.m ; j ++) {
15                         for (int k = 0 ; k < x.m ; k ++) {
16                                 ll tmp = x[i][k] * y[k][j] ;
17                                 res[i][j] += tmp ;
18                         }
19                 }
20         }
21         return res ;
22 }

 

矩阵快速幂模板

标签:

原文地址:http://www.cnblogs.com/get-an-AC-everyday/p/4691915.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!