Consider following $3\times 3$ matrix.
$\begin{pmatrix}3&6&9\\ 2& 4 &8\\ 1 &5& 7 \end{pmatrix}$
I need to find combination of three numbers where each number comes from unique column & row. For example $3,6,8$ is not what I want as $3$ and $6$ are from same row.
$6,4,7$ is also not right because $6$ and $4$ are from same columns.
$3,4,7$ is valid as each number comes from different column and row.
Next thing I want, is to find combination whose sum is minimum compared to sum of all other possible combinations. For example $3,4,7$ will be final answer if $3+4+7 = \min$. How do I find this for $n \times n$ matrix?
This is known as the assignment problem. The best-known algorithm for solving it is the Hungarian algorithm.