【矩阵快速幂】
来源:互联网 发布:讯飞语音输入法 mac 编辑:程序博客网 时间:2024/06/14 07:12
1.21矩阵快速幂模板
typedef long long LL;const int mod = ;struct Matrix{ LL v[4][4];};Matrix multiply(Matrix x, Matrix y, int Matrix_len);/*矩阵乘法*/Matrix matrix_pow(Matrix a, int k, int Matrix_len);/*矩阵快速幂*/Matrix multiply(Matrix x, Matrix y, int Matrix_len){ Matrix z; memset(z.v, 0, sizeof(z.v)); for(int i = 0; i < Matrix_len; i++){ for(int j = 0; j < Matrix_len; j++){ for(int k = 0; k < Matrix_len; k++){ z.v[i][j] += x.v[i][k] * y.v[k][j]; z.v[i][j] %= mod; } } } return z;}Matrix matrix_pow(Matrix a, int k, int Matrix_len){ Matrix b; for(int i = 0; i < Matrix_len; i++){ for(int j = 0; j < Matrix_len; j++){ i == j? b.v[i][j] = 1: b.v[i][j] = 0; } } while(k){ if(k & 1) b = multiply(b, a, 2); a = multiply(a, a, 2); k >>= 1; } return b;}
阅读全文
1 0
- 快速矩阵快速幂
- 转移矩阵+矩阵快速幂
- 矩阵乘法 矩阵快速幂
- 构造矩阵+矩阵快速幂
- 矩阵快速幂,矩阵加法,矩阵乘法
- 快速幂||矩阵快速幂
- 快速幂&矩阵快速幂
- 快速幂,矩阵快速幂
- 快速幂 矩阵快速幂
- 快速幂&矩阵快速幂
- 【快速幂】【矩阵快速幂】
- 快速幂和快速矩阵
- poj3070--矩阵 快速幂
- POJ3233矩阵快速幂
- poj3070Fibonacci 矩阵快速幂
- 矩阵的快速幂
- 矩阵快速幂
- 矩阵的快速幂
- 作业2:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153 是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。
- 【错误】安装Vim出现错误kde-config-telepathy-accounts > 15.04
- Python判断中文字符串是否相等
- BZOJ 4033: [HAOI2015]树上染色 树形dp
- Java运行时异常和非运行时异常
- 【矩阵快速幂】
- 二叉树的前序、中序和后序遍历
- Java SE Primer——集合框架 完全解析
- addfilterQuery方法 OR 的solr查询
- 研究生三年的规划
- Java笔记总结(二)--switch-case小结
- 1065. A+B and C (64bit) (20)
- 如何在MyBatis中使用枚举
- 设置 Dialog 不显示标题的常用方法