all combinations of k elements out of n

后端 未结 5 2148
星月不相逢
星月不相逢 2020-12-01 03:23

Can somebody provide me a link or pseudocode of a function for finding all combinations of k elements out of n? possibly in STL. I don\'t need to compute n choose k, I need

5条回答
  •  爱一瞬间的悲伤
    2020-12-01 03:32

    Here is a lazy example of pseudocode that can get the job done...

    void nChooseK(array[n],k){
        recurse("",array[n],k);      
    }
    
    void recurse(initialString,array[n],k){
        if(k == 0){
            print initialString;
            return;
         }
        for(i=0;i

提交回复
热议问题