# "SOPC2017: Come Together" problem

Problem
Can anyone explain how to solve this problem ?

This problem is known as the assignment problem. It’s a classical problem so I’m sure you will find many tutorials to solve it if you search online. I’m not familiar with it myself, but a quick search reveals the Hungarian Algorithm is commonly applied.

1 Like

This is one of the classic problems of type Assignment problem or Hungarian Problems!
Say we have N workers and N jobs that should be done. For each pair (worker, job) cost of job is known.
We have to complete all tasks while minimizing total cost.

The algorithm works as follows:

If a number is added to or subtracted from all of the entries of any one row or column of a cost matrix, then an optimal assignment for the resulting cost matrix is also an optimal assignment for the original cost matrix.

1. For each row of the matrix, find the smallest element and subtract it from every element in its row.
2. Do the same (as step 1) for all columns.
3. Cover all zeros in the matrix using minimum number of horizontal and vertical lines.
4. Test for Optimality: If the minimum number of covering lines is n, an optimal assignment is possible and
we are finished. Else if lines are lesser than n, we haven’t found the optimal assignment, and must
proceed to step 5.
5. Determine the smallest entry not covered by any line. Subtract this entry from each uncovered row, and

Check this topcoder link to get to know about the algorithm behind solving this:
Hungarian Algorithm

1 Like

Thanks @meooow , can you give any link on the implementation of Hungarian algorithm