// Contoh Bab 11: menelusuri semua urutan dengan next_permutation. // // Compile: g++ -std=c++17 -O2 -o urutan exercises/11/03-semua-urutan.cpp // Jalankan: ./urutan // Contoh masukan: 3 #include #include using namespace std; int main() { int n; cin >> n; int p[16]; for (int i = 0; i < n; i++) p[i] = i; sort(p, p + n); // harus terurut sebelum mulai long long banyak = 0; do { banyak++; if (n <= 4) { for (int i = 0; i < n; i++) cout << p[i] << " "; cout << "\n"; } } while (next_permutation(p, p + n)); cout << "banyak urutan: " << banyak << "\n"; return 0; }