We are given three values , and where is number of rows in matrix, is number of columns in the matrix and is the number that can have only two values -1 and 1. Our aim is to find the number of ways of filling the matrix of such that the product of all the elements in each row and each column is equal to . Since the number of ways can be large we will output
Input : n = 2, m = 4, k = -1
Output : 8
Following configurations satisfy the conditions:-
Input : n = 2, m = 1, k = -1
Output : The number of filling the matrix
From the above conditions, it is clear that the only elements that can be entered in the matrix are 1 and -1. Now we can easily deduce some of the corner cases
If k = -1, then the sum of number of rows and columns cannot be odd because -1 will be present odd number of times in each row and column therefore if the sum is odd then answer is .
If n = 1 or m = 1 then there is only one way of filling the matrix therefore answer is 1.
If none of the above cases are applicable then we fill the first rows and the first columns with 1 and -1. Then the remaining numbers can be uniquely identified since the product of each row an each column is already known therefore the answer is .
Please Login to comment...