1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std;
typedef long long LL;
const int maxn = 505; const int INF = 0x3f3f3f3f; const int MOD = 1e9+7;
struct Matrix{ LL arr[maxn][maxn]; int n,m; Matrix operator * (const Matrix &b)const{ Matrix res; memset(res.arr,0,sizeof(res.arr)); for(int i = 0;i < n;i++) for(int j = 0;j < b.m;j++) for(int k = 0;k < m;k++){ (res.arr[i][j] += arr[i][k] * b.arr[k][j] % MOD) %= MOD; } res.n = n;res.m = b.m; return res; } }a,b,ans;
int main(){ int n,p,m; scanf("%d %d %d",&n,&p,&m); a.n = n;a.m = p; for(int i = 0;i < n;i++) for(int j = 0;j < p;j++){ scanf("%lld",&a.arr[i][j]); } b.n = p;b.m = m; for(int i = 0;i < p;i++) for(int j = 0;j < m;j++){ scanf("%lld",&b.arr[i][j]); } ans = a * b; for(int i = 0;i < n;i++){ for(int j = 0;j < m - 1;j++){ (ans.arr[i][j] += MOD) %= MOD; printf("%lld ",ans.arr[i][j]); } (ans.arr[i][m - 1] += MOD) %= MOD; printf("%lld\n",ans.arr[i][m - 1]); } return 0; }
|