ポイント
- next_permutation/prev_permutationを使う
- do-while文を使う
- 事前に配列をソートしておく
vector<int> arr = { 3, 1, 4, 7, 2 };
// 昇順探索
sort(arr.begin(), arr.end());
do {
for (int x : arr) cout << x << " ";
cout << endl;
} while (next_permutation(arr.begin(), arr.end()));
// 降順探索
sort(arr.rbegin(), arr.rend());
do {
for (int x : arr) cout << x << " ";
cout << endl;
} while (prev_permutation(arr.begin(), arr.end()));