Now I'm researching about communications of n cars, the problem I meet can be simplified as:
n numbers, and I want to get all the subsets, which meet the condition that they are divided (like the example below) and all these n numbers are ** all used and used only once**.
Such as if n = 3, I can divide them to:
[[1, 2, 3]]
[[1, 2], [3]]
[[1, 3], [2]]
[[2, 3], [1]]
[[1], [2], [3]]
I've tried to solve it by next_permutation function using c++(because it doesn't have any function for combination problems) but failed because it output too many repeated answers(such as [1 2][3]
and [2 1][3]
, which are actually the same but I don't know how to recognize them)
I think my idea is wrong using this function.