51nod1113【矩阵快速幂】
思路:
裸的矩阵快速幂,读完题,感觉有点对不起四级算法题这一类。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
int n;
struct asd{
LL a[102][102];
}; asd mul(asd x,asd y)
{
asd ans;
memset(ans.a,0,sizeof(ans.a));
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
for(int k=0;k<n;k++)
ans.a[i][j]=(ans.a[i][j]+x.a[i][k]*y.a[k][j]%mod)%mod;
return ans;
} asd quickmul(int g,asd x)
{
asd ans;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(i==j) ans.a[i][j]=1;
else ans.a[i][j]=0;
while(g)
{
if(g&1) ans=mul(ans,x);
x=mul(x,x);
g>>=1;
}
return ans;
} int main()
{
int m;
scanf("%d%d",&n,&m);
asd x;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
scanf("%lld",&x.a[i][j]);
x=quickmul(m,x);
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(j) printf(" ");
printf("%lld",x.a[i][j]);
}
puts("");
}
return 0;
}
51nod1113【矩阵快速幂】的更多相关文章
- 51nod1113(矩阵快速幂模板)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1113 题意:中文题诶- 思路:矩阵快速幂模板 代码: #inc ...
- [51nod1113]矩阵快速幂
解题关键:模板题,方便以后熟悉 #include<bits/stdc++.h> using namespace std; typedef long long ll; struct mat{ ...
- 51nod 1113 矩阵快速幂( 矩阵快速幂经典模板 )
1113 矩阵快速幂 链接:传送门 思路:经典矩阵快速幂,模板题,经典矩阵快速幂模板. /******************************************************* ...
- 矩阵快速幂 HDU 4565 So Easy!(简单?才怪!)
题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Go ...
- 51nod 算法马拉松18 B 非010串 矩阵快速幂
非010串 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 如果一个01字符串满足不存在010这样的子串,那么称它为非010串. 求长度为n的非010串的个数.(对1e9+7取模) ...
- 51nod 1113 矩阵快速幂
题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> ...
- 【66测试20161115】【树】【DP_LIS】【SPFA】【同余最短路】【递推】【矩阵快速幂】
还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. ...
- HDU5950(矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 题意:f(n) = f(n-1) + 2*f(n-2) + n^4,f(1) = a , f(2 ...
- 51nod 1126 矩阵快速幂 水
有一个序列是这样定义的:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. 给出A,B和N,求f(n)的值. Input 输 ...
随机推荐
- VirtualBox创建VM结果ProcessorType是空的
用WMI来查询CPU的频率,一直没问题: "Select MaxClockSpeed From Win32_Processor Where ProcessorType = 3" 结 ...
- mysql一:操作数据库
创建数据库是指在数据库空间中划出一块空间用来存储相关的数据,表就是存储在对应的数据库里面.首先来看下查看数据库的命令:show databases. 这个是用来查询数据库空间下所有的数据库,其中inf ...
- Error: Failed to fetch plugin E:_My_File______workMyCodemyCodecordova-workspaceplugman-testMyMath via registry. Probably this is either a connection problem, or plugin spec is incorrect.
$ cordova plugin add E:\_My_File_____\_work\MyCode\myCode\cordova-workspace\plugman-test\MyMath --sa ...
- 使用 Docker LNMP 部署 PHP 运行环境
简介 Docker LNMP 是基于 Docker 的 PHP 集成开发环境. Github 地址:https://github.com/YanlongMa/docker-lnmp 包含软件 ngin ...
- LeetCode:划分字母区间【763】
LeetCode:划分字母区间[763] 题目描述 字符串 S 由小写字母组成.我们要把这个字符串划分为尽可能多的片段,同一个字母只会出现在其中的一个片段.返回一个表示每个字符串片段的长度的列表. 示 ...
- java.sql.SQLException: Illegal connection port value '3306:success'
严重: Servlet.service() for servlet jsp threw exceptionjava.sql.SQLException: Illegal connection port ...
- Java多线程系列 基础篇05 synchronized关键字
1. synchronized原理 在java中,每一个对象有且仅有一个同步锁,所以同步锁是依赖于对象而存在.当我们调用某对象的synchronized方法时,就获取了该对象的同步锁.例如,synch ...
- P5111 zhtobu3232的线段树
P5111 zhtobu3232的线段树 维护左子树右子树的贡献和跨区间贡献 #include<bits/stdc++.h> using namespace std; typedef lo ...
- Android WiFi系统架构【转】
本文转载自:http://blog.csdn.net/liuhaomatou/article/details/40398753 在了解WIFI模块的系统架构之前.我心中就有一个疑问,那么Android ...
- html的head中的常见元素
<head></head>中有charset, title,link 操作系统默认的字符编码就是gbk. html的加强 (1)<a href="#" ...