Matrix Operations Topic (continually updated)
\ (1 \) matrix multiplication
\ (2 \) Mr. toluene string
Matrix Multiplication
Details: Also take the time to die before the explosion negative output answer.
$View$ $Code$
// omitted header file using namespace std; inline int read() { int K = 0, f = 1; char ch=getchar(); while(ch>'9'||ch<'0') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { K = (right << 1) + (right << 3) + CH-'0 '; ch=getchar(); } Return right * f; } const int mod=1e9+7; int n,p,m,a[505][505],b[505][505],c[505][505]; int main () { n=read(); p=read(); m=read(); for(register int i=1;i<=n;i++) for(register int j=1;j<=p;j++) a[i][j]=read(); for(register int i=1;i<=p;i++) for(register int j=1;j<=m;j++) b[i][j]=read(); for(register int i=1;i<=n;i++) for(register int j=1;j<=m;j++) for(register int k=1;k<=p;k++) c[i][j]=(c[i][j]+1ll*a[i][k]*b[k][j])%mod; for(register int i=1;i<=n;i++) { for(register int j=1;j<=m;j++) printf("%d ",(c[i][j]+mod)%mod); printf("\n"); } return 0; }