算法可变大小项目兼顾到大致平衡的套 [英] Algorithm to balance variably-sized items into roughly-balanced sets

查看:184
本文介绍了算法可变大小项目兼顾到大致平衡的套的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种算法来拆分不同大小成N的数同样大小群的项目的列表。

具体而言,我在C#中的ASP.NET网站工作在那里我有一个字符串(数据库检索)名单。该字符串是长短不一的。我有一组其需要显示的字符串列。我需要一个算法,将找到最平衡的套(项目顺序是不相关),以便最终列要尽可能平衡。

抽象例:

创建3列。

产品分配:

   - 项目A  - 身高5
  -  B项 - 高3
  -  C项 - 身高7
  -  D项 - 身高2
  -  E项 - 高3
 

所需的输出:

 专栏1:项目A,D项
专栏2:C项
第3栏:项目B,E项
 

解决方案

做的最快的是可能只是将每个新项目到最小的名单(其中最小是所有项目的大小之和列表)。

I'm seeking an algorithm to split a list of items of varying sizes into "N" number of similarly-sized groups.

Specifically, I'm working on an ASP.NET site in C# where I have a (database-retrieved) list of strings. The strings are of varying lengths. I have a set of columns which need to display the strings. I need an algorithm that will find the most balanced sets (item order is irrelevant) to allow the final columns to be as balanced as possible.

Abstracted Example:

Creating 3 columns.

Items to distribute:

 - Item A - height 5
 - Item B - height 3
 - Item C - height 7
 - Item D - height 2
 - Item E - height 3

Desired output:

Column 1: Item A, Item D
Column 2: Item C
Column 3: Item B, Item E

解决方案

The quickest thing to do is probably just insert each new item into the smallest list (where "smallest" is the sum of the sizes of all the items in the list).

这篇关于算法可变大小项目兼顾到大致平衡的套的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆