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 输 ...
随机推荐
- c语言高速推断一个数是偶数还是奇数
#include <stdio.h> int main() { int a; while(1) { printf("please input the number:\n" ...
- java和js互调 webview
public class JavaAndJSActivity extends Activity implements View.OnClickListener { private EditText e ...
- 【转】Unicode(UTF-8, UTF-16)令人混淆的概念
参考地址:http://www.cnblogs.com/kingcat/archive/2012/10/16/2726334.html Java中,char类型用UTF-16编码描述一个代码单元 为啥 ...
- TensorFlow Action(开山使用篇)
1.TensorFlow安装: 使用pip install tensorflow安装CPU版: 或使用pip install tensorflow-gpu==1.2.1指定版本安装GPU版. 2.Te ...
- ubuntu tomcat 配置及使用细节
1.改端口号(两个) vi server.xml 一个是http协议端口 <Connector port="8091" protocol="HTTP/1.1&qu ...
- 蓝色科技AE宣传片头光晕视频
蓝色科技AE宣传片头光晕视频素材,蓝色AE炫光素材,科技AE片头,精美,AE特效,绚丽,AE模板,视频素材,动画. 地址:http://www.huiyi8.com/xuanguang/ae/
- laravel基础课程---5、路由复习(路由作用)
laravel基础课程---5.路由复习(路由作用) 一.总结 一句话总结: 有利于百度收录,及SEO优化 1.路由书写 (D:\laravel\yzmedu\yzm2\routes\web.php) ...
- 练习E-R图书管理数据库
- L89
His voice was hoarse after several hours' speech.Attributive adjectives precede the noun.I gave the ...
- android自定义控件(一) 官方文档的翻译
构建自定义组件 Android中,你的应用程序程序与View类组件有着一种固定的联系,例如按钮(Button).文本框(TextView),可编辑文本框(EditText),列表框(ListView) ...