loj #100. 矩阵乘法

矩阵乘法板子

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define int long long
#define ll long long 
using namespace std;
const ll mod=1000000007;
ll n,a,b,m,p;
struct re{
	int rec[501][501];
}ans,tem,org;
re tim(re x,re y){
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			tem.rec[i][j]=0;
			for(int k=1;k<=p;++k){
				tem.rec[i][j]+=(x.rec[i][k]%mod)*(y.rec[k][j]%mod);
				tem.rec[i][j]%=mod;
			}
		}
	}
	return tem;
}
signed main(){
	scanf("%lld%lld%lld",&n,&p,&m);
	for(int i=1;i<=n;++i){
		for(int j=1;j<=p;++j){
			scanf("%lld",&org.rec[i][j]);
		}
	}
	for(int i=1;i<=p;++i){
		for(int j=1;j<=m;++j){
			scanf("%lld",&ans.rec[i][j]);
		}
	}
	ans=tim(org,ans);
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			cout<<(ans.rec[i][j]+mod)%mod<<" ";
		}
		cout<<endl;
	}
	return 0;
}
原文地址:https://www.cnblogs.com/For-Miku/p/14424132.html