Maximize sum of table where each number must come from unique row and column

后端 未结 2 1649
滥情空心
滥情空心 2020-12-28 09:35

Suppose we have a table of numbers like this (we can assume it is a square table):

20  2   1   3   4
5   1   14  8   9
15  12  17  17  11
16  1   1   15  18
         


        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-28 10:39

    This is the maximum cost bipartite matching problem. The classical way to solve it is by using the Hungarian algorithm.

    Basically you have a bipartite graph: the left set is the rows and the right set is the columns. Each edge from row i to column j has cost matrix[i, j]. Find the matching that maximizes the costs.

提交回复
热议问题