title: exactly one value in each row and column of a matrix
body: <p><br>
  I'm trying to find out which is the best approach for this problem:
  There is a matrix like this:</p>
  
  <pre><code>1 0 0 1 0
  1 1 0 1 0
  1 1 0 0 1
  0 0 1 1 0
  1 0 1 0 0
  </code></pre>
  
  <p>We want to find out every possible matrix where only one 1 is in each row and column, for example this matrix is a possible solution:</p>
  
  <pre><code>1 0 0 0 0
  0 1 0 0 0
  0 0 0 0 1
  0 0 0 1 0
  0 0 1 0 0
  </code></pre>
  
  <p>I think you can find a solution with looping throug each possible combination and check if there is exactly one 1 in each row and column? Is there any known algorithm for this?
  Is is possible to actually calculate the solution and not trying out every possibility?</p>
  
  <p>Thank you very much!</p>
  
  <p>Edit:
  One possible solution (but expensive) could be to generate every theoretically possible matrix, for example (using 3x3 matrix because it's shorter):
  1.</p>
  
  <pre><code>1 0 0
  0 1 0
  0 0 1
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>1 0 0
  0 0 1
  0 1 0
  </code></pre>
  
  <p>3.</p>
  
  <pre><code>1 0 0
  0 0 1
  0 1 0
  </code></pre>
  
  <p>4.  </p>
  
  <pre><code>0 1 0
  1 0 0
  0 0 1
  </code></pre>
  
  <p>5.</p>
  
  <pre><code>0 1 0
  0 0 1
  1 0 0
  </code></pre>
  
  <p>etc.</p>
  
  <p>Then we could check for every generated matrix if the original matrix has the 1s at the given positions. If yes, it's a solution.</p>
  
  <p>Which loops would you need to generate all these matrices?</p>