矩阵快速幂模板
来源:互联网 发布:wecut美图软件 编辑:程序博客网 时间:2024/06/05 14:16
#include<map>#include<set>#include<queue>#include<stack>#include<vector>#include<math.h>#include<cstdio>#include<sstream>#include<numeric>//STL数值算法头文件#include<stdlib.h>#include <ctype.h>#include<string.h>#include<iostream>#include<algorithm>#include<functional>//模板类头文件using namespace std;typedef long long ll;const int maxn=20;const int INF=0x3f3f3f3f;const int mod=9973;int n,m;struct mat{ int arr[maxn][maxn];} str;mat mul(mat& A,mat& B){ mat res; memset(res.arr,0,sizeof(res.arr)); for(int i=0; i<n; i++) for(int j=0; j<n; j++) for(int k=0; k<n; k++) res.arr[i][j]=((res.arr[i][j]+A.arr[i][k]*B.arr[k][j])%mod+mod)%mod; return res;}mat pow(mat &A,int k){ mat M; memset(M.arr,0,sizeof(M.arr)); for(int i=0; i<n; i++) M.arr[i][i]=1; while(k) { if(k&1) M=mul(M,A); A=mul(A,A); k>>=1; } return M;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d %d",&n,&m); for(int i=0; i<n; i++) for(int j=0; j<n; j++) scanf("%d",&str.arr[i][j]); int sum=0; str=pow(str,m); for(int i=0; i<n; i++) sum+=str.arr[i][i]; printf("%d\n",sum%mod); } return 0;}
阅读全文
0 0
- 矩阵快速幂模板
- 矩阵快速幂--模板
- 矩阵快速幂 模板
- 矩阵快速幂模板
- 矩阵快速幂模板
- 【矩阵快速幂模板】
- 矩阵快速幂模板
- 矩阵快速幂模板
- 矩阵快速幂模板
- 矩阵快速幂【模板】
- 矩阵快速幂模板
- 矩阵快速幂模板
- 矩阵快速幂模板
- 矩阵快速幂模板
- 矩阵快速幂模板
- 矩阵快速幂模板
- 矩阵快速幂 【模板】
- 快速矩阵幂模板
- 向梦想出发
- 初识jQuery
- 简单线程实验
- 51Nod-1031 骨牌覆盖【递推】
- IO流之序列化和反序列化
- 矩阵快速幂模板
- opencv3_java 图像的Scalar标量合成 AddScalar
- Java基础--Java访问权限控制(访问权限修饰词)
- 南阳理工第八题
- codeforces802 J&&K Send the Fool Further! (easy&&medium) -- 树形DP
- oj 2002: C语言实验——单词统计
- servlet学习(一)
- Restore IP Addresses
- 多态、向上转型与向下转型