#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int mod=;
int n;
struct matrix
{
int f[][];
}; matrix mul(matrix a,matrix b)
{
int i,j,k;
matrix c;
memset(c.f,,sizeof(c.f));
for(k=;k<n;k++)
{
for(i=;i<n;i++)
{
for(j=;j<n;j++)
{
c.f[i][j]+=a.f[i][k]*b.f[k][j];
c.f[i][j]%=mod;
}
} }
return c;
} matrix pow_mod(matrix a,int b)
{
matrix s;
int t;
memset(s.f,,sizeof(s.f));
for(int i=;i<n;i++)
{
s.f[i][i]=;
}
while(b)
{ t=b%;
b/=;
if(t!=)
s=mul(s,a);
a=mul(a,a);
}
return s;
} int main()
{
int t,k;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&k) ;
matrix e;
for(int i=;i<n;i++)
for(int j=;j<n;j++)
{
scanf("%d",&e.f[i][j]);
} e=pow_mod(e,k);
int ans=;
for(int i=;i<n;i++)
ans=(ans+e.f[i][i])%mod;
printf("%d\n",ans);
} return ;
}

hdu 1575 矩阵连乘2的更多相关文章

  1. HDU - 1575——矩阵快速幂问题

    HDU - 1575 题目: A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的和),现要求Tr(A^k)%9973.  Input数据的第一行是一个T,表示有T组数据. 每组数据的第一行有n( ...

  2. hdu 1575(矩阵快速幂)

    Tr A Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  3. HDU 1575 矩阵快速幂裸题

    题意:中文题 我就不说了吧,... 思路:矩阵快速幂 // by SiriusRen #include <cstdio> #include <cstring> using na ...

  4. Tr A HDU 1575 (矩阵快速幂)

    #include<iostream> #include<vector> #include<string> #include<cmath> #includ ...

  5. hdu 1575 矩阵快速幂模板

    #include "iostream" #include "vector" #include "cstring" using namespa ...

  6. HDU 1575 Tr A(矩阵高速幂)

    题目地址:HDU 1575 矩阵高速幂裸题. 初学矩阵高速幂.曾经学过高速幂.今天一看矩阵高速幂,原来其原理是一样的,这就好办多了.都是利用二分的思想不断的乘.仅仅只是把数字变成了矩阵而已. 代码例如 ...

  7. HDU.1575 Tr A ( 矩阵快速幂)

    HDU.1575 Tr A ( 矩阵快速幂) 点我挑战题目 题意分析 直接求矩阵A^K的结果,然后计算正对角线,即左上到右下对角线的和,结果模9973后输出即可. 由于此题矩阵直接给出的,题目比较裸. ...

  8. hdu 4291 矩阵幂 循环节

    http://acm.hdu.edu.cn/showproblem.php?pid=4291 凡是取模的都有循环节-----常数有,矩阵也有,并且矩阵的更奇妙: g(g(g(n))) mod 109  ...

  9. HDU 1575 Tr A 【矩阵经典2 矩阵快速幂入门】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1575 Tr A Time Limit: 1000/1000 MS (Java/Others)    Me ...

随机推荐

  1. 静态构造函数c# 静态块java initallize oc

    静态构造函数c# 静态块java initallize oc 先看一道常见题目,以下代码的执行结果是什么? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 ...

  2. ZBrush中Z球(ZSphere和ZSphereⅡ)

    ZSphere可以让用户使用干净的拓扑结构快速建立一个基础网格,然后将其塑造成任何形状.ZSphere的强大在于它非常简单,用户可以从一个单一的ZSphere开始,然后轻松地在其上面增加新的ZSphe ...

  3. div隐藏但是依然占位置

    <!doctype html> <html> <head> <meta charset="utf-8"> <script ty ...

  4. 'Upgrade' header is missing

    spring-websocket 握手失败是因为 有拦截器  注释掉拦截器就OK

  5. mysql 修改默认的引擎

      需求: mysql 的默认的引擎为MyISAM  虽然该引擎访问的速度快,但并不支持存储事物,也不支持外键,所以我们修改为innob Linux修改MySql默认存储引擎为InnoDB     一 ...

  6. python scrapy爬取HBS 汉堡南美航运公司柜号信息

    下面分享个scrapy的例子 利用scrapy爬取HBS 船公司柜号信息 1.前期准备 查询提单号下的柜号有哪些,主要是在下面的网站上,输入提单号,然后点击查询 https://www.hamburg ...

  7. 数组中出现一次的两个数(三个数)& 求最后一位bit为1

    对于两个数,对于结果中,剩余bit1来异或区分. 下面的解法,非常精简: int lastBitOf1(int number) { ); } void getTwoUnique(vector<i ...

  8. SQL的四种语言:DDL、DML、DCL、TCL

    1. DDL(Data Definition Language) 数据库定义语言statements are used to define the database structure or sche ...

  9. LeetCode 232: Implement Queue using Stacks

    Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...

  10. HDU 2196 Computer(求树上每一个节点到其他点的最远距离)

    解题思路: 求出树的直径的两个端点.则树上每一个节点到其它点的最远距离一定是到这两个端点的距离中最长的那一个. #include <iostream> #include <cstri ...