博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
51nod 1122:机器人走方格 V4 (矩阵快速幂)
阅读量:6966 次
发布时间:2019-06-27

本文共 1265 字,大约阅读时间需要 4 分钟。

昨天上随机信号分析讲马氏链的时候突然想到这题的解法,今天写一下

定义矩阵A,Ans=A^n,令A[i][j]表示,经过1次变换后,第i个位置上的机器人位于第j个位置的情况数,则Ans[i][j]表示最初在第i个位置上的机器人n次变换后位于第j个位置的情况数

最后求一下任意两个机器人不在相同位置的情况数之和(注意乘法原理和加法原理的应用)

#include
using namespace std;typedef long long LL;const int N=4;const LL mod=1e9+7;LL hh[N][N]= {
{
0,1,1,1}, {
1,0,1,1}, {
1,1,0,1}, {
1,1,1,0}};struct Mat{ LL mat[N][N]; Mat() { memset(mat,0,sizeof(mat)); } LL* operator [](int x) //注意这种写法 { return mat[x]; }} A;Mat Mut(Mat a,Mat b){ Mat c; for(int k=0; k
>=1) { if(n&1) c=Mut(c,a); a=Mut(a,a); } return c;}void init_A(){ for(int i=0; i
>n) { Mat Ans=Qpow(A,n); LL sum=0; for(int i1=0; i1<4; i1++) for(int i2=0; i2<4; i2++) for(int i3=0; i3<4; i3++) for(int i4=0; i4<4; i4++) if(i1!=i2&&i1!=i3&&i1!=i4&&i2!=i3&&i2!=i4&&i3!=i4) { sum+=Ans[0][i1]*Ans[1][i2]%mod*Ans[2][i3]%mod*Ans[3][i4]%mod; sum%=mod; } cout<
<

 

转载于:https://www.cnblogs.com/Just--Do--It/p/6597505.html

你可能感兴趣的文章
sublime text 2 c++编译 环境 问题小结
查看>>
MySQL索引分析
查看>>
20170829
查看>>
android项目获得所有运行程序
查看>>
Volley框架学习
查看>>
css中常用的标签
查看>>
android studio无线真机调试------Android
查看>>
jsp指令与动作
查看>>
C++中关键字的理解--Static
查看>>
简述Core Location定位功能
查看>>
html搜索,文中的关键字变色
查看>>
Python标准库_ sys,random,time
查看>>
[Android开发Tips]Bean的定义
查看>>
less
查看>>
PrestaShop 网站后台配置(三)
查看>>
【Win8启动后自动进入传统桌面设置】
查看>>
GP通过外部表装载数据时遇到ERROR:extra data after last expected column解决方法
查看>>
hdu2639,第K优决策
查看>>
hdu1166 敌兵布阵
查看>>
gcd(辗转相除法)
查看>>