矩阵乘法
title: 矩阵乘法
categories:
- ICPC
tags:
- null
abbrlink: 4ad33c6a
date: 2024-10-04 00:00:00
int n, m;
int k;
struct matrix{
int c[101][101];
matrix(){memset(c,0,sizeof c);}
};
matrix operator*(matrix &a,matrix &b){
matrix t;
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++){
for(int g=1;g<=m;g++){
t.c[i][j]+=a.c[i][g]*b.c[g][j];
}
}
}
return t;
}
void solve(){
cin>>n>>m>>k;
matrix a,b;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a.c[i][j];
}
}
for(int i=1;i<=m;i++){
for(int j=1;j<=k;j++){
cin>>b.c[i][j];
}
}
matrix ans=a*b;
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++){
cout<<ans.c[i][j]<<" ";
}
cout<<endl;
}
}
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 爱飞鱼的blog!