我有一组尺寸和目标尺寸。使用一些背包算法,我得到了所有可能的答案。因此,所有答案都具有相同的总和,但包含不同数量的元素。我首先按计数排序,以便获得最大数量的元素。现在,我留下了一个子集,它们具有相同的总和和相同的数量。
以下是一个示例(实际上有很多很多答案):
[24, 33, 21, 22],
[24, 26, 27, 23],
[24, 27, 28, 21],
[34, 23, 21, 22],
[26, 23, 29, 22],
[24, 40, 36],
[34, 26, 40],
[30, 38, 32],
[24, 37, 39],
[40, 38, 22],
现在,我想把那些拥有最大元素的元素带到顶端(¡不破坏内部秩序!):
[24, 26, 27, 23], <-- 23 is the biggest smallest
[26, 23, 29, 22], <-- 22 is the second biggest smallest
[24, 27, 28, 21], <-- 21, 24 is the biggest second smallest
[24, 33, 21, 22], <-- 21, 22, 24 is the biggest third smallest
[34, 23, 21, 22], <-- 21, 22, 23 is the second biggest third smallest
[30, 38, 32], <-- 30 is the biggest smallest
[34, 26, 40], <-- 26 is the second biggest smallest
[24, 37, 39], <-- 24, 37 is the biggest second smallest
[24, 40, 36], <-- 24, 36 is the second biggest second smallest
[40, 38, 22], <-- 22 is the fourth biggest smallest
如果这对您有意义,那么请告诉我可以处理它的排序算法的名称。到目前为止我发现的所有内容都只需要使用内部数组的一个固定元素进行排序,但我想使用尽可能多的元素来进行排序。
显然,我可以通过蛮力来做到这一点,但我希望有一个已经存在的优雅解决方案。我只是不知道要搜索的正确关键字。
谢谢!