二次联通门 : 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, " "[j == M]); return 0; }