题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; ; ; int n, m; struct Mat{//矩阵 ll mat[N][N]; }; Mat operator * (Mat a, Mat b){//一次矩阵乘法…
#include <iostream> #include <algorithm> #include <cmath> #define MOD 7 #define N 2 using namespace std; struct Matrix { long long v[N][N]; }; //矩阵间的乘法%m Matrix matrix_mul(Matrix A, Matrix B, long long m) { Matrix ans; ; i < N; i++) {…
首先建立矩阵,给每个格子编号,然后在4*4的格子中把能一步走到的格子置为1,然后乘n次即可,这里要用到矩阵快速幂 #include<iostream> #include<cstdio> using namespace std; const int mod=1e9+7; long long n,ans; struct qwe { long long a[5][5]; qwe operator * (qwe b) { qwe c; for(long long i=1;i<=4;i…