题目链接

题意:A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的和),现要求Tr(A^k)%9973。

思路:简单的矩阵高速幂

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm> using namespace std; //typedef long long ll;
typedef __int64 ll; const int MOD = 9973;
const int N = 15; ll k;
int n; struct mat{
int s[N][N];
mat() {
memset(s, 0, sizeof(s));
}
mat operator * (const mat& c) {
mat ans;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
for (int k = 0; k < N; k++)
ans.s[i][j] = (ans.s[i][j] + s[i][k] * c.s[k][j]) % MOD;
return ans;
}
}; mat state; mat pow_mod(ll k) {
if (k == 1)
return state;
mat a = pow_mod(k / 2);
mat ans = a * a;
if (k % 2)
ans = ans * state;
return ans;
} int main() {
int cas;
scanf("%d", &cas);
while (cas--) {
scanf("%d%I64d", &n, &k);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
scanf("%d", &state.s[i][j]);
mat c = pow_mod(k);
int ans = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i == j)
ans += c.s[i][j];
printf("%d\n", ans % MOD);
}
return 0;
}

题目链接

HDU1575-Tr A(矩阵高速幂)的更多相关文章

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

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

  2. hdu1575 Tr A 矩阵快速幂模板题

    hdu1575   TrA 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1575 都不需要构造矩阵,矩阵是题目给的,直接套模板,把对角线上的数相加就好 ...

  3. HDU1575:Tr A(矩阵快速幂模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1575   #include <iostream> #include <string.h> ...

  4. hdu 1575 Tr A(矩阵高速电源输入)

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

  5. UVA 11551 - Experienced Endeavour(矩阵高速幂)

    UVA 11551 - Experienced Endeavour 题目链接 题意:给定一列数,每一个数相应一个变换.变换为原先数列一些位置相加起来的和,问r次变换后的序列是多少 思路:矩阵高速幂,要 ...

  6. UVA10518 - How Many Calls?(矩阵高速幂)

    UVA10518 - How Many Calls?(矩阵高速幂) 题目链接 题目大意:给你fibonacci数列怎么求的.然后问你求f(n) = f(n - 1) + f(n - 2)须要多少次调用 ...

  7. HDU2842-Chinese Rings(递推+矩阵高速幂)

    pid=2842">题目链接 题意:求出最少步骤解出九连环. 取出第k个的条件是,k-2个已被取出,k-1个仍在支架上. 思路:想必九连环都玩过吧,事实上最少步骤就是从最后一个环開始. ...

  8. HDU2276 - Kiki &amp; Little Kiki 2(矩阵高速幂)

    pid=2276">题目链接 题意:有n盏灯.编号从1到n.他们绕成一圈,也就是说.1号灯的左边是n号灯.假设在第t秒的时候,某盏灯左边的灯是亮着的,那么就在第t+1秒的时候改变这盏灯 ...

  9. uva 10655 - Contemplation! Algebra(矩阵高速幂)

    题目连接:uva 10655 - Contemplation! Algebra 题目大意:输入非负整数,p.q,n,求an+bn的值,当中a和b满足a+b=p,ab=q,注意a和b不一定是实数. 解题 ...

随机推荐

  1. Tomcat之——配置项目有虚拟路径

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/47024863 非常easy,在Tomcat的Server.xml文件里的Host节 ...

  2. 华为PUSH SDK 接入方法

    本文参考了华为推送平台官网及其Demo:http://developer.huawei.com/cn/consumer/wiki/index.php?title=%E6%8E%A5%E5%85%A5% ...

  3. android缩放动画的两种实现方法

    在android开发.我们会常常使用到缩放动画,普通情况下缩放动画有两种实现方式.一种是直接通过java代码去实现,第二种是通过配置文件实现动画,以下是两种动画的基本是用法: Java代码实现: // ...

  4. heap-adb shell查看堆栈使用

    今天在使用eclipse中的heap查看oom的时候,发现手机(eng版本)非常的卡,后来换成usr版本,又连接不上eclipse.最后听别人说,可以使用adb shell进行查看.指令如下 adb ...

  5. 1.25 Python知识进阶 - 封装

    封装 示例代码: class Role(object): count = 0 def __init__(self,name,role,weapon,life_value=100,money=15000 ...

  6. HttpUtility.UrlEncode,Server.UrlEncode 的区别

    引用: 1.HttpUtility.UrlEncode,HttpUtility.UrlDecode是静态方法,而Server.UrlEncode,Server.UrlDecode是实例方法. 2.Se ...

  7. Large Division (大数求余)

    Given two integers, a and b, you should check whether a is divisible by b or not. We know that an in ...

  8. JavaScript--Module模式

    //module: Module模式是JavaScript编程中一个非常通用的模式 window.onload = function() { //1.基本使用: var MyFn = function ...

  9. win7打不开chm格式文件

           近期在开发的过程中,发现重装的系统Wind7 打不开java帮助文档.搜索了半天才找到. 在这里分享一下. 一.假设不能打开,可这样恢复文件关联: 1.開始执行,输入:regsvr32 ...

  10. C#string转换为Datetime

    DateTime.ParseExact("0710090000", "MMddHHmmss", CultureInfo.CurrentCulture, Date ...