http://www.yudd97.com/archives/148
void Matmul(LLX[MAXN][MAXN],LL Y[MAXN][MAXN])
{
LL t[MAXN][MAXN]={0};
for(int i=0;i<N;i++)
for(int k=0;k<N;k++)
if(X[i][k])
for(int j=0;j<N;j++)
t[i][j]=(t[i][j]+X[i][k]*Y[k][j]);
for(int i=0;i<N;i++)
for(int j=0;j<N;j++)
X[i][j]=t[i][j];
}
HDOJ 4920 Matrixmultiplication
Problem Description
Given two matrices A and B of size n×n, find the product of them.
bobo hates big integers. So you are only asked to find the result modulo 3.
bobo hates big integers. So you are only asked to find the result modulo 3.
Input
The input consists of several tests. For each tests:
The first line contains n (1≤n≤800). Each of the following n lines contain n integers — the description of the matrix A. The j-th integer in the i-th line equals Aij. The next n lines describe the matrix B in similar format (0≤Aij,Bij≤109).
The first line contains n (1≤n≤800). Each of the following n lines contain n integers — the description of the matrix A. The j-th integer in the i-th line equals Aij. The next n lines describe the matrix B in similar format (0≤Aij,Bij≤109).
Output
For each tests:
Print n lines. Each of them contain n integers — the matrix A×B in similar format.
Print n lines. Each of them contain n integers — the matrix A×B in similar format.
单独考察矩阵相乘的题目并不多见,普遍都是结合矩阵快速幂,高斯消元等矩阵算法。进行这些算法之前我们必须要掌握矩阵相乘算法
我们需掌握简单的相乘规则,才能学习后面的一些矩阵算法。同时,为了以后学习算法以及做题的需要,我们也要记得矩阵相乘时的算法复杂度及优化细节。