hdu1575 Tr A(矩阵快速幂模板题)
来源:互联网 发布:淘宝上差评怎么删除 编辑:程序博客网 时间:2024/05/16 00:26
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1575
矩阵快速幂,感觉和整数快速幂是一样的,二分真是好东西。
#include<cstdio>#include<cstring>using namespace std;const int num=15;const int mod=9973;struct matrix{ int m[num][num];};matrix p,c;int n;void init(matrix &a){ int i,j; for(i=0;i<n;i++) for(j=0;j<n;j++) a.m[i][j]=(i==j);}matrix mul(matrix &a,matrix &b){ matrix c; int i,j,k; memset(c.m,0,sizeof(c.m)); for(i=0;i<n;i++) for(j=0;j<n;j++) for(k=0;k<n;k++) { c.m[i][j]+=(a.m[i][k]*b.m[k][j]); c.m[i][j]%=mod; } return c;}int main(){ int t,i,j,k,ans; //freopen("in.txt","r",stdin); scanf("%d",&t); while(t--) { scanf("%d%d",&n,&k); init(p); for(i=0;i<n;i++) for(j=0;j<n;j++) scanf("%d",&c.m[i][j]); while(k>0) { if(k&1) p=mul(p,c); c=mul(c,c); k=(k>>1); } ans=0; for(i=0;i<n;i++) ans+=p.m[i][i]; printf("%d\n",ans%mod); } return 0;}
0 0
- hdu1575 Tr A(矩阵快速幂模板题)
- hdu1575 Tr A(矩阵快速幂模板题)
- HDU1575--Tr A(矩阵快速幂模板)
- hdu1575 Tr A(矩阵快速幂)
- HDU1575 Tr A(矩阵快速幂)
- hdu1575 Tr A(矩阵快速幂)
- hdu1575 Tr A (矩阵快速幂)
- hdu1575 Tr A(矩阵快速幂)
- (矩阵快速幂)hdu1575 Tr A
- hdu1575 Tr A (矩阵快速幂)
- Hdu1575 - Tr A - 矩阵快速幂
- HDU1575-Tr A(矩阵快速幂)
- HDU1575 Tr A 【矩阵快速幂】
- hdu1575 Tr A 矩阵快速幂
- [矩阵快速幂]hdu1575 Tr A
- HDU1575 Tr A【矩阵快速幂】
- hdu1575 Tr A(矩阵快速幂)题解
- HDU1575(矩阵快速幂模板题)
- 判断点是否在矩形内碰撞代码
- node.js实现提交简单的form表单
- POJ-3259 Wormholes
- 成功的反义词不是失败,而是从未行动。有一天你总会明白,遗憾比失败更让你难以面对。
- Spring 接收转换 jquery ajax json数组字符串
- hdu1575 Tr A(矩阵快速幂模板题)
- Java冒泡排序
- Ubuntu下 ssh : connect to host localhost port 22:Connection refused
- msdn关于内存泄漏检测
- 在Win8系统中修改hosts文件无法保存的解决方法
- IArea
- android开发之setFocusable()和 setFocusableInTouchMode()方法的区别
- 13.JavaWeb基础 监听器
- Interleaving String