next_permutation();
可以用于可重, 或者不可重集, 寻找下一个排列.
时间复杂度尚不明.
//适用于不可重和可重集的排列. # include <iostream> # include <algorithm> using namespace std; int a[1003], n; int main() { cin >> n; for (int i = 0; i < n; ++i ) cin >> a[i]; sort(a, a+n); do { for(int i = 0; i < n; ++i) cout << a[i] << ‘ ‘; cout << endl; } while( next_permutation(a, a+n) ); return 0; }