HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Linear Data Structures: Arrays > problem:


50592 - Matrix Multiplication

Guest
• Review clarifications (1)

Section problems

• 50616 - Snake
• 50647 - Spiral
• 50543 - Hotel rooms
• 50271 - Factorial
• 50419 - The longest bitonic sequence
• 50326 - Matrix Operations
• 50329 - Draw Matrix-1
• 50541 - Binary to decimal
• 50592 - Matrix Multiplication
• 50606 - Long product
• 50607 - Long sum
• 50319 - Toll Plazas
• 50318 - Product Info
• 50360 - National Elections
• 50337 - Exam Averages
• 50567 - Input Data Normalization

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