HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Array and Matrices > problem:


50592 - Matrix Multiplication

Guest
• Review clarifications (1)

Volume problems

• 50555 - Frequency of Letters
• 50558 - Biggest Barn
• 50563 - Long Modulus
• 50565 - Binary numbers
• 50567 - Input Data Normalization
• 50569 - 12th Grade Elective Subjects
• 50585 - Inner Product
• 50587 - Modular Conversion
• 50592 - Matrix Multiplication
• 50594 - Transformations
• 50653 - Long Divide
• 50767 - Censor
• 50768 - Where is Waldorf?
• 50792 - The student with the highest...
• 51182 - Count and Sum 2
• 51193 - The max element of k-th co...
• 51196 - The sum of two arrays

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Ibrahim Mesecan.

Matrix Multiplication

Shqip

Mr. Erjon is a mathematician. In many cases, he needs to multiply matrices with other matrices.

When multiplying two matrices, the left matrix rows are multiplied with the right matrix columns. Every left row element is multiplied with every right column element and then summed up. For example, when the first row and the second column elements are multiplied and summed, the result is placed to the first row and the second column in the resulting matrix. Thus, inner dimensions must be the same. And, the outer dimensions are the dimensions of the resulting matrice.

According to the figure on the right:

  • Matrix A has 4 rows and 2 columns;
  • Matrix B has 2 rows and 3 columns;
  • Thus, matrix res will have 4 rows and 3 columns;
Then, the matrix multiplication for every row and column element of the resulting array will be carried out as follows:
   res11 = (a11, a12)*(b11, b21) = (a11.b11) + (a12.b21)
   res12 = (a11, a12)*(b12, b22) = (a11.b12) + (a12.b22)
      .       .
      .       .
   res33 = (a31, a32)*(b13, b23) = (a31.b13) + (a32.b23)
      .       .
      .       .
      .       .

Question:
To help Mr. Erjon, write a program that is going to receive two 2D matrices and multiply them.

Input specification
First, you will be given three integers: m, n and k where the first matrix has m rows and n columns, and the second matrix has n rows and k columns and 1 < m, n , k ≤ 100. The following m rows contain n integers and for the first matrix, and then, the following n rows contain k integers for the second matrix. Matrix elements are positive integers that are less than 7000 and thus the results are in integer limits.

Output specification
Give m rows and k columns of integer numbers that represent the resulting matrix.

Sample Input I
  2 3 2
  3 4 2
  1 0 1
  1 4
  2 0
  4 4
Sample Output I  
  19 20
  5 8
 Sample Input II
  3 2 3
  1 4
  2 0
  4 4
  3 4 2
  1 0 1
 Sample Output II
  7 4 6
  6 8 4
  16 16 12

Для отправки решений необходимо выполнить вход.

www.contester.ru