What is an algorithm to split a group of items into 3 separate groups fairly?

自古美人都是妖i 提交于 2019-12-05 04:33:19

Tough homework problem. This is essentially the optimization version of the 3-partition problem.

http://en.wikipedia.org/wiki/3-partition_problem

It is closely related to bin packing, partition, and subset-sum (and, as you noted, knapsack). However, it happens to be strongly NP-Complete, which makes it a harder than its cousins. Anyway, I suggest you start by looking at dynamic programming solutions to the related problems (I'd start with partition, but find a non-wikipedia explanation of the DP solution).

Update: I apologize. I have mislead you. The 3-partition problem splits the input into sets of 3, not 3 sets. The rest of what I said still applies, but with the renewed hope that your variant isn't strongly np-complete.

Let f[i][j][k] denotes whether it is possible to have value j in the first set and value k in the second set, with the first i items.

So we have f[i][j][k] = f[i-1][j-v[i]][k] or f[i-1][j][k-v[i]].

and initially we have f[0][0][0] = True.

for every f[i][j][k] = True, update your answer depends on how you defines fairly.

I don't know about "The Best" mathematically speaking, but one obvious approach would be to build a population of groups initially with one item in each group. Then, for as long as you have more groups than the desired number of final groups, extract the two groups with the lowest values and combine them into a new group that you add back into the collection. This is similar to how Huffman compression trees are built.

Example:

1 3 7 9 10
becomes
4(1+3) 7 9 10
becomes
9 10 11(1+3+7)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!