number of combinations for 5x5 matrix where up to one cell in each row and column can be selected

2k Views Asked by At

If I have a 5 x 5 matrix, how many different combinations are there if up to one cell in each row and column can be selected and how do I work this out, i.e. at most 5 selected cells without collision in row or column?

For example,

[ x, 0, 0, 0, 0
  0, x, 0, 0, 0
  0, 0, x, 0, 0
  0, 0, 0, x, 0
  0, 0, 0, 0, x]

is one option

but it could easily be

[ x, 0, 0, 0, 0
  0, x, 0, 0, 0
  0, 0, x, 0, 0
  0, 0, 0, x, 0
  0, 0, 0, 0, 0]

[ x, x, 0, 0, 0
  0, 0, 0, 0, 0
  0, 0, x, 0, 0
  0, 0, 0, x, 0
  0, 0, 0, 0, x]

is not allowed.

1

There are 1 best solutions below

1
On BEST ANSWER

If you place $k$ ones, you can choose rows in $\binom5k$ ways, choose columns in $\binom5k$ ways, and assign them to each other in $k!$ ways, so the total number of options is

$$ \sum_{k=0}^5\binom5k^2k!=5!^2\sum_{k=0}^5\frac1{k!(5-k)!^2}=1546 $$

(Wolfram|Alpha computation).