Matrix multiplication---Blue bridge cup

Source: Internet
Author: User

Problem Description enter two matrices, each of which is the m*s,s*n size. Outputs the result of multiplying the two matrices. Input Format The first line, a space separated by three positive integers m,s,n (none more than 200).
The next M line, an integer separated by a space of s per line, represents matrix A (I,J).
Next S line, an integer separated by n spaces per line, represents matrix B (i,j).
output Format m line, an integer separated by n spaces per line, and the value of Matrix C (i,j) after the output is multiplied. Sample Input 2 3 2
1 0-1
1 1-3
0 3
1 2
3 1
Sample Output -3 2
-8 2

Tips
The matrix C should be a M row n column, where C (i,j) equals the inner product of the line vector of line I of matrix A and the matrix B J column vector.

For example, C (All) = (1,0,-1) * (0,1,3) = 1 * 0 +0*1+ (-1) *3=-3



Problem Solving Analysis:

The topic here is the basic method of linear algebra, if you do not know how to find the matrix product of Baidu a bit.


Code:

#include <iostream>
#include <cstring>
using namespace Std;
int main ()
{


int m,s,n;
cin>>m>>s>>n;
int a[m+1][s+1];
int b[s+1][n+1];
int c[m+1][n+1];
Memset (C,0,sizeof (c));
int i,j,k;
for (i=1;i<=m;i++)
for (j=1;j<=s;j++)
cin>>a[i][j];
for (i=1;i<=s;i++)
for (j=1;j<=n;j++)
cin>>b[i][j];
for (k=1;k<=s;k++)
for (i=1;i<=m;i++)
for (j=1;j<=n;j++)
C[I][J]+=A[I][K]*B[K][J];
for (i=1;i<=m;i++)
{
for (j=1;j<=n;j++)
{
cout<<c[i][j];
if (j!=n)
cout<< "";
}
cout<<endl;
}
return 0;
}



Matrix multiplication---Blue bridge cup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.