LibreOJ #100. 矩阵乘法

二次联通门 : LibreOJ #100. 矩阵乘法

 

 

 

 

 

/*
    LibreOJ #100. 矩阵乘法
    
    矩阵乘法
    
    注意两个矩阵宽与高相乘的顺序 
*/
#include <cstdio>

#define Max 500
#define Mod 1000000007

int main (int argc, char *argv[])
{
    static long long a[Max + 1][Max + 1], b[Max + 1][Max + 1];

    int N, P, M;
    
    scanf("%d %d %d", &N, &P, &M);

    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= P; j++)
            scanf("%lld", &a[i][j]);

    for (int i = 1; i <= P; i++)
        for (int j = 1; j <= M; j++)
            scanf("%lld", &b[i][j]);

    static long long c[Max + 1][Max + 1];
    
    for (int i = 1; i <= N; i++)
        for (int k = 1; k <= P; k++)
            for (int j = 1; j <= M; j++)
            
                (c[i][j] += a[i][k] * b[k][j]) %= Mod;

    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= M; j++)
        
            printf("%lld%c", (c[i][j] % Mod + Mod) % Mod, " \n"[j == M]);
    
    return 0;
}

 

posted @ 2017-06-24 19:55  ZlycerQan  阅读(200)  评论(0编辑  收藏  举报