Permutation 排列

问题

从包含nn个不同元素的集合s=[x0,x1,x2,,xn1]s = [ x_0, x_1, x_2, \dots , x_{n-1} ]中任意取mm个元素(mnm \leq n),组成的所有排列。其中任意两元素互不相同。

解法

在Full Permutation和Combination的基础上,从拥有nn个元素的ss中选取mm个元素,可得到n!m!(nm)!\frac{n!}{m! \cdot (n-m)!}个组合。遍历所有组合进行全排列,即为所求。

该算法的时间复杂度为O(Pmn)=O(n!(nm)!)O(P_m^n) = O( \frac {n!} {(n-m)!} )

源码

Permutation.h

Permutation.cpp

测试

PermutationTest.cpp

Last updated