Each row must have at least an element with value 1.
Say we have 3 by 4 matrix. Then an acceptable arrangement would be:
x x 1 x x x x 1 x 1 x x
and there will be:
4! / (4-3)! = 24
different allowed permutations of a 3 by 4 matrix.
Say for a 4 by 5 matrix, violations would be
1 x x x 1 x x x x x x x x 1 x x x x 1 x
where first row has more than one values of 1, and column 4 has the same violation. Lastly, there is no 1 value in row 2.
Similarly number of allowed permutations would be:
5! / (5-4)! = 120
that is, the number of different matrices.
My attempt is through different for loops, which is cumbersome for larger elements. Any smarter way to make this happen?
Thank you.
Best Answer