最大化幸福的算法

标签 algorithm

假设您有:

  • 100 人
  • 100 个项目

每个人都按照他们希望从事的顺序对所有 100 个项目进行排序。什么样的算法可以用来最大化人们的幸福感(即被分配到他们排名更高的项目转化为更大的幸福感)。

假设每个人一个项目。

最佳答案

这类问题的算法非常流行,被称为匈牙利算法。用这类问题解决的类似问题:

We consider an example where four jobs (J1, J2, J3, and J4) need to be executed by four workers (W1, W2, W3, and W4), one job per worker. The matrix below shows the cost of assigning a certain worker to a certain job. The objective is to minimize the total cost of the assignment.

来源:http://www.hungarianalgorithm.com/examplehungarianalgorithm.php

请注意,默认的匈牙利算法会找到最小成本,但您可以更改程序以使其以最大化成本的方式运行。

If the goal is to find the assignment that yields the maximum cost, the problem can be altered to fit the setting by replacing each cost with the maximum cost subtracted by the cost.

来源:http://en.wikipedia.org/wiki/Hungarian_algorithm

我已经在我的 Github 上实现了匈牙利算法, 所以请随意使用它并修改它以使其发挥最大的成本。

关于最大化幸福的算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24247758/

相关文章:

c++ - 有没有办法从下面的数据中唯一地构建一个整数?

algorithm - NLP语法: fixing a to an?

algorithm - 轮廓绘图算法

Javascript排序函数将元素放在数组的中间

algorithm - Paxos 的真实世界示例

javascript - 我如何计算数组的模式并忽略数据

c++ - 计算所有对之间的曼哈顿距离

algorithm - 按 2D 属性排列 block 而不重叠

javascript - 在 javascript 中搜索具有 id 的 child

algorithm - 在线排序算法和外部排序算法有什么区别?