There are n workers and n tasks. Assigning worker i to task j costs
cost[i][j]. Each worker must be assigned exactly one distinct task (a
perfect matching). Find the minimum possible total cost.
Line 1: integer n (1 ≤ n ≤ 18)
Next n lines: n integers each — row i is cost[i][0..n-1]
(1 ≤ cost[i][j] ≤ 1000)
A single integer: the minimum total assignment cost.
Input:
3
9 2 7
6 4 3
5 8 1
Output:
9
Explanation: assign worker 1 to task 2 (cost 2), worker 2 to task 1 (cost 6),
worker 3 to task 3 (cost 1) — total 2 + 6 + 1 = 9.
Case 1
2 1 2 2 1
2
Case 2
3 9 2 7 6 4 3 5 8 1
9
Input
2 1 2 2 1
Expected Output
2
Run or submit your code to see output here.