algorithm - 具有偶数个元素的集合的划分

标签 algorithm discrete-mathematics

<分区>

是否有任何有效的方法可以将集合 {1, ... , 2*n} 的所有划分列成 n 对?

最简单的想法是列出所有排列,然后排列 (a1, a2, ... , a8) 表示除法 {{a1,a2}, ... , {a7 ,a8}}。在这种情况下,每个分区都有 2^n * n! 排列。这是 O((2n)!)

我能找到更有效的方法吗?

最佳答案

这是我的纸笔算法:

f(set,result):
  if the set is empty:
    return result
  otherwise:
    pair one item from the set with
    each of the remaining items,
    calling f again with the pair added to
    the result and out of the set

123456
12 34 56
   35 46
   36 45
13 24 56
   25 46
   26 45
14 23 56
   25 36
   26 35
...

关于algorithm - 具有偶数个元素的集合的划分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33372926/

相关文章:

python - 解析 "ordered"列表并找到相应的和和加数的算法?

algorithm - 在图中找到 X 成本最低的树

algorithm - 文档分类,使用遗传算法

c# - 文件去斑 - OCR

python - 在 python 中计算体积或表面积的好算法

c++ - 帕尔马多面体库 : Vertex Enumeration

algorithm - 为什么这个指数在这个例子中以这种方式计算?

python - 我们可以使用映射来搜索而不是二分搜索吗?

algorithm - 双向图中的传递闭包

近似整数分配问题最优解的算法