#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<double> vec;
typedef vector<vec> mat;
const int INF=0x3f3f3f3f;
const int MAX_N=100;
mat mul(mat &A,mat &B){
mat C(A.size(),vec(B[0].size()));
for(int i=0;i<A.size();i++){
for(int j=0;j<B[0].size();j++){
for(int k=0;k<A[0].size();k++){
C[i][j]+=A[i][k]*B[k][j];
}
}
}
return C;
}
mat qpow(mat A,ll n){
mat B(A.size(),vec(A.size()));
for(int i=0;i<B.size();i++)B[i][i]=1;
while(n>0){
if(n&1)B=mul(B,A);
A=mul(A,A);
n>>=1;
}
return B;
}
void show(mat &A){
for(int i=0;i<A.size();i++){
for(int j=0;j<A[0].size();j++){
cout<<A[i][j]<<" ";
}
cout<<endl;
}
}
C++矩阵相乘、矩阵快速幂
最新推荐文章于 2024-02-10 22:20:09 发布