WA求调
  • 板块AT_dp_r Walk
  • 楼主zxr_zwgh
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/12 14:03
  • 上次更新2024/7/12 15:07:36
查看原帖
WA求调
979363
zxr_zwgh楼主2024/7/12 14:03
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
struct node{
	long long a[105][105];
	int r,c;
	node(int _r=0,int _c=0){
		r=_r,c=_c;
		memset(a,0,sizeof a);
	}
	void unit(){
		memset(a,0,sizeof a);
		for(int i=1;i<=r;i++) a[i][i]=1;
	}
	node operator+(const node &t) const{
		node ans=*this;
		for(int i=1;i<=r;i++){
			for(int j=1;j<=c;j++){
				ans.a[i][j]+=t.a[i][j]%mod;
				ans.a[i][j]%=mod;
			}
		}
		return ans;
	}
	node operator-(const node &t) const{
		node ans=*this;
		for(int i=1;i<=r;i++){
			for(int j=1;j<=c;j++){
				ans.a[i][j]-=t.a[i][j];
			}
		}
		return ans;
	}
	node operator*(const node &t) const{
		node ans(r,t.c);
		int n=r,m=t.c;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				for(int k=1;k<=c;k++){
					ans.a[i][j]+=a[i][k]%mod*t.a[k][j]%mod;
					ans.a[i][j]%=mod;
				}
			}
		}
		return ans;
	}
	void out(){
		for(int i=1;i<=r;i++){
			for(int j=1;j<=c;j++){
				cout<<a[i][j]<<" ";
			}
			cout<<endl;
		}
	}
	node ksm(long long b){
        node a=*this;
        node ans(r,c);
        ans.unit();
        while(b){
            if(b&1) ans=ans*a;
            a=a*a;
            b>>=1;
        }
        return ans;
    }
};
int main(){
	node c;
	int n,k;
	scanf("%d%d",&n,&k);
	c.c=c.r=n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>c.a[i][j];
		}
	}
	c=c.ksm(k);
	long long ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			ans+=c.a[i][j];
			ans%=mod;
		}
	}
	cout<<ans;
	return 0;
}

RT,最后一个样例没过

2024/7/12 14:03
加载中...