需要算法不同大小的组文件转换成近似相等的块
-
13-09-2019 - |
题
我试图找出一种算法,这将有助于我组大小不等到发言权的文件的分类,“N”近似相等大小的组。
这是如何实现这一目标的任何想法?
解决方案
Find the target group size. This is the sum of all sizes divided by n.
Create a list of sizes.
Sort the files decreasing in size.
for each group
while the remaining space in your group is bigger than the first element of the list
take the first element of the list and move it to the group
for each element
find the elemnet for which the difference between group size and target group size is minimal
move this elemnt to the group
这不会产生最佳结果,但很容易实现,并让你很好的效果。为最优解需要穷举搜索是NP完全。
不隶属于 StackOverflow