Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 一组n算法中k个对象的置换_C#_Algorithm_Permutation_Combinations_Combinatorics - Fatal编程技术网

C# 一组n算法中k个对象的置换

C# 一组n算法中k个对象的置换,c#,algorithm,permutation,combinations,combinatorics,C#,Algorithm,Permutation,Combinations,Combinatorics,我正在寻找一种有效的方法来实现这一点: 你有一组数字,假设我们的集合等于4(N=4) 必须生成3个元素(K=3)的所有排列 N=4和K=3时的输出: 1 2 3 1 2 4 1 3 2 1 3 4 1 4 2 1 4 3 2 1 3 2 1 4 2 3 1 2 3 4 2 4 1 2 4 3 3 1 2 3 1 4 3 2 1 3 2 4 3 4 1 3 4 2 4 1 2 4 1 3 4 2 1 4 2 3 4 3 1 4 3 2 任何人都有一个很好的快速算法或网络参考 谢谢 类似于以下伪代

我正在寻找一种有效的方法来实现这一点:

  • 你有一组数字,假设我们的集合等于4(N=4)
  • 必须生成3个元素(K=3)的所有排列 N=4和K=3时的输出:

    1 2 3
    1 2 4
    1 3 2
    1 3 4
    1 4 2
    1 4 3
    2 1 3
    2 1 4
    2 3 1
    2 3 4
    2 4 1
    2 4 3
    3 1 2
    3 1 4
    3 2 1
    3 2 4
    3 4 1
    3 4 2
    4 1 2
    4 1 3
    4 2 1
    4 2 3
    4 3 1
    4 3 2
    
    任何人都有一个很好的快速算法或网络参考


    谢谢

    类似于以下伪代码:

    permute(set, output, len)  //output will hold all the permutations
    
    for each number in the set do
        choose number and store it at output[0]
        if(!empty(set))
            call permute(set{without the number}, output + (len - 1)!, len-1) //adjust the position
    

    通过
    permute调用(set,output,k)

    @Woot4Moo欢迎您提出批评,只要我在声明中说得更清楚,很难推断原始的
    输出+1
    是指输出的指数,还是指它是要增加之前的值1。这个问题已经回答了一百次了。请在发布前搜索您的主题。标记。@Tylerduden进行此操作的一般方法是投票选择完全相同的近似值。@Tylerduden:有一些熟悉的主题您是对的,我已经检查过了,但是有一个区别,您有N个元素(N=K)的排列,而不是N个元素集合中K个对象的排列。您不能比O(N!/(N-K)!)复杂性,因为这是排列的数量。@icepack:那么我应该改变算法的概念!:(