all combinations of k elements out of n

后端 未结 5 2157
星月不相逢
星月不相逢 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:33

    Create an auxiliary vector with n - k zeros followed by k ones. A zero means the element in the original container is not included, whereas one means the element is included.

    Now use std::next_permutation on the auxiliary vector to get the next combination.

提交回复
热议问题