问题
I want to generate permutations of n numbers, where there is no two permutations which are reversions of each other (the first one read from the last character to the first is the same as the second one). For instance, n = 3, I want to generate:
1 2 3 //but not 3 2 1
1 3 2 //but not 2 3 1
2 1 3 //but not 3 1 2
I do not care which one of the two will be generated. The algorith should be applicable for large n (>20). Is there any such algorithm or a way to check if the generated permutations is a mirror of previously generated one?
回答1:
Use std::next_permutation
and ignore permutations whose first element is larger than its last.
回答2:
No, By usual hardware and software upto this days, you cannot do this, because the number of such a permutations is 20!/2 > 10^10 * 2^20, means you need many years to generate them.
来源:https://stackoverflow.com/questions/19081579/generating-permutations-which-are-not-mirrors-of-each-other