9 条题解

  • -14
    @ 2021-9-26 8:13:50

    不会把还有人不知道矩阵乘法

    #include<bits/stdc++.h>
    #define int long long//记得开longlong
    using namespace std;
    const int N = 600, M = 1e9 + 7;
    int a[N][N], b[N][N];
    inline int max(int x, int y){return x > y ? x : y;}
    inline int min(int x, int y){return x > y ? y : x;}
    inline int read(){
    	int x = 0, f = 1; char c = getchar();
    	while (!isdigit(c)){if (c == '-') f = -1; c = getchar();}
    	while (isdigit(c)){x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); }
    	return x * f;
    }
    inline void write(int x){
    	if (x < 0) {x = ~(x - 1); putchar('-');}
    	if (x > 9) write(x / 10);
    	putchar(x % 10 ^ 48);
    }
    signed main(){
    	int n = read(), p = read(), m = read();
    	for (int i = 1; i <= n; i ++)
    	    for (int j = 1; j <= p; j ++)
    	        a[i][j] = (read() + M) % M;//记得取模
    	for (int i = 1; i <= p; i ++)
    	    for (int j = 1; j <= m; j ++)
    	        b[i][j] = (read() + M) % M;//记得取模
    	for (int i = 1; i <= n; i ++){
    	    for (int j = 1; j <= m; j ++){
    	    	int sum = M;
    	    	for (int k = 1; k <= p; k ++)
    	    	    sum = (sum + a[i][k] * b[k][j]) % M;
    	    	write(sum % M);putchar(' ');
    		}
    		puts("");
    	}
    	return 0;
    }

    信息

    ID
    60
    时间
    2000ms
    内存
    256MiB
    难度
    3
    标签
    递交数
    803
    已通过
    203
    上传者