How to generate permutations where a[i] != i?

后端 未结 6 531
野的像风
野的像风 2021-01-18 12:11

Suppose I have an array of integers int a[] = {0, 1, ... N-1}, where N is the size of a. Now I need to generate all permutations of

6条回答
  •  醉话见心
    2021-01-18 12:53

    If you have access to C++ STL, use next_permutation, and do an additional check of a[i] != i in a do-while loop.

提交回复
热议问题