hdu1575 Tr A
来源:互联网 发布:瓷砖设计的软件 编辑:程序博客网 时间:2024/05/22 13:08
矩阵快速幂取模
一定要每一步都取模!否则WA.
#include <cstdio>#include <cstring>using namespace std;int x,n,k,mod=9973;struct Matrix{ int pos[11][11]; friend Matrix operator*(Matrix a,Matrix b) { Matrix c; memset(c.pos,0,sizeof(c.pos)); for(int i=0;i<n;i++) for(int j=0;j<n;j++) { for(int k=0;k<n;k++) { c.pos[i][j]+=(a.pos[i][k]*b.pos[k][j])%mod; } c.pos[i][j]%=mod; } return c; }}matrix;/*void debug(Matrix a){ for(int i=0;i<n;i++) { for(int j=0;j<n;j++) printf("%d\t",a.pos[j][i]); puts(""); } puts("");}*/int tr(Matrix tmp){ //debug(tmp); Matrix res; memset(res.pos,0,sizeof(res.pos)); for(int i=0;i<n;i++) res.pos[i][i]=1; for(int i=0;k>>i;i++) { int num=k>>i; if(num&1) res=res*tmp; tmp=tmp*tmp; } int cnt=0; for(int i=0;i<n;i++) cnt=(cnt+res.pos[i][i])%mod; //printf("cnt:%d\n",cnt); return cnt;}int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&k); for(int i=0;i<n;i++) for(int j=0;j<n;j++) scanf("%d",&matrix.pos[i][j]); //debug(matrix); printf("%d\n",tr(matrix)%mod); } return 0;}
0 0
- hdu1575 Tr A
- Tr A hdu1575
- 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(矩阵快速幂)
- openstack学习之keystone
- C#获取当前应用程序所在路径及环境变量
- 十七、Android无法访问本地服务器(localhost)的解决方案
- Android客户端简单的聊天程序实现
- 银行卡四位加空格
- hdu1575 Tr A
- 在ASP.NET项目中使用CKEditor
- JdbcTemplate的用法
- OCP-1Z0-051 补充题库 第1题 TRUNCATE命令的使用
- 使用sockets:从新闻组中获取文章(一)
- struts2在前台通过property获取属性值某些字符转义问题
- hive使用案例
- 内存对齐的规则以及作用
- php实战第九天