let's say , a course with 8 participans, i must output the first 3 places in all possible ways. ex :
123 124 125 126 127 128 213 so on..
I know there is next_permutation algorithm but it returns all the possible permuations with all the numbers (from 1 through 8), but i need first 3 places with all the participans
ex:
1 2 3 4 5 6 7 8
1 2 3 4 5 6 8 7
The things you're after are not permutations, which is why next_permutation alone won't solve your problem.
First, you need to decide whether 123 is the same as 321 or not. If they are the same, you have plain combinations. If they are different, you have k-permutations (different from plain permutations).
std::next_permutation gives you the next permutation, not the next k-permutation. There's no std::next_combination.
Fortunately, if you write your own next_combination (or find one on the internet), you can use it and std::next_permutation together to easily express the next_k_permutation algorithm.
With the correct terminology at hand it should be easy to find a solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With