从动态尺寸的安置静态大小排列(Static sized permutations from Dyna

2019-10-31 11:39发布

我怎样才能得到一个列表,其中组合尺寸只需是静态的如所有组合。 如果列表中有4个元素,那么只有需要长度为4不是3,2和1。我猜这将需要递归的排列。 独特的组合将是有益的,但我想看到它在简单的为我的小狗功率(无独特性?)的形式。

Answer 1:

set s = { x1, x2, x3, x4 };
array solution;

permute( i ) =>
    if( i == 0 ) => print and return;

    while unused elements in set =>
        take element from set which is not in solution;
        put element in solution;
        permute( i - 1 );
        remove element from solution;

如果你想更具体的答案,你必须创建一个更具体的问题。 显示部分代码/工作/什么..



文章来源: Static sized permutations from Dynamic sized set