2009-08-13 27 views

回答

6
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完整搜索。

2

K means可能會幫助你。研究更高級的聚類算法是一個很好的起點,但考慮到你的問題是一維的,k-means應該足夠了。

+0

如何使用K-means來解決這個問題? OP希望「大小大致相同的組」,而不是包含類似尺寸項目的羣集 – bubaker 2009-08-14 15:10:04

+0

嗯......你確定嗎?如果操作符在兩種不同的上下文中使用大小,他應該更加明確: - 無論如何,我說找到更合適的聚類方法是一個好的開始。 – fortran 2009-08-16 21:35:31

相關問題