板子

功能性

重载

bool operator< (const nood&a)const

编译

g++ A.cpp -o A -std=c++14 -O2

-Wl,-stack=134217728

算法

矩阵快速幂(P3390)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
ll n,m;
struct nood{
    ll a[105][105];
    nood(){
        memset(a,0,sizeof(a));
    }
}a;
nood operator *(const nood&x,const nood&y){
    nood z;
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                z.a[i][j]=(z.a[i][j]+x.a[i][k]*y.a[k][j]%mod)%mod;
            }
        }
    }
    return z;
} 
int main(){
	cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>a.a[i][j];
        }
    }
    nood ans;
    for(int i=1;i<=n;i++){
        ans.a[i][i]=1;
    }
    while(m){
        if(m&1){
            ans=ans*a;
        }
        a=a*a;
        m>>=1;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cout<<ans.a[i][j]<<" ";
        }
        cout<<endl;
    }
}
posted @ 2025-11-13 20:48  MistyPost  阅读(3)  评论(0)    收藏  举报