Tr A
来源:互联网 发布:怎么制作淘宝网站 编辑:程序博客网 时间:2024/06/05 06:00
05月 23日。
简单的矩阵快速幂。
Tr A
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 18 Accepted Submission(s) : 15
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
每组数据的第一行有n(2 <= n <= 10)和k(2 <= k < 10^9)两个数据。接下来有n行,每行有n个数据,每个数据的范围是[0,9],表示方阵A的内容。
Output
Sample Input
22 21 00 13 999999991 2 34 5 67 8 9
Sample Output
22686
Author
Source
#include <iostream>
#include<string.h>
using namespace std;
int a,b;
struct node
{
int jz[11][11];
};
node cheng(node qqqq,node pppp)
{
node f;
for(int i=1;i<=a;i++)
for(int j=1;j<=a;j++)
{
f.jz[i][j]=0;
for(int k=1;k<=a;k++)
{
f.jz[i][j]=qqqq.jz[i][k]*pppp.jz[k][j]+ f.jz[i][j];
}
f.jz[i][j]=f.jz[i][j]%9973;
}
return f;
}
int main()
{
int n;
cin>>n;
while(n--)
{
cin>>a>>b;
node q,ans;
for(int i=1;i<=a;i++)
for(int j=1;j<=a;j++)
{
cin>>q.jz[i][j];
if(i==j)
ans.jz[i][j]=1;
else
ans.jz[i][j]=0;
}
while(b)
{
if(b%2==1)
{
ans=cheng(q,ans);
}
b=b/2;
q=cheng(q,q);
}
int sum=0;
for(int i=1;i<=a;i++)
{
sum=sum+ans.jz[i][i];
sum=sum%9973;
}
cout<<sum<<endl;
}
return 0;
}
- Tr A
- Tr A
- Tr A
- Tr A
- Tr A
- Tr A
- Tr A
- Tr A
- Tr A hdu 1575
- HDOJ 1575 - Tr A
- hdu 1575 Tr A
- hdu1575 Tr A
- Tr A(矩阵)
- 题目59:Tr A
- HDU 1575 Tr A
- Tr A hdu1575
- HDU 1575 Tr A
- hdu 1575 Tr A
- OC学习之路(4)
- UVA232解题报告
- 大文件读:
- EventBus封装
- error 997:重叠I/O正在进行中(mircosoft vc++ 2008 Redisturbute x64 )
- Tr A
- Nginx location配置
- lower_bound/upper_bound使用方法
- E. Read Time
- Android Design Support Library
- 用 Git 命令上传项目到 Github
- Solr6.5.1 主从复制
- 为什么要写博客?转发
- 中值滤波C++实现