fork download
  1.  
  2.  
  3. #include <bits/stdc++.h>
  4. #define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
  5. #define fi first
  6. #define se second
  7. #define el "\n"
  8. #define pb push_back
  9. #define sz(a) (int)a.size()
  10. #define FILL(a, x) memset(a, x, sizeof(a))
  11.  
  12. using namespace std;
  13. typedef long long ll;
  14. typedef pair<int, int> ii;
  15. const int N = (int)1e6+3;
  16. int n, k;
  17. int a[100];
  18. bool F[100];
  19.  
  20. void Xl(){
  21. /// In ra day nhi phan do dai n
  22. FOR(i, 1, n) cout << a[i] << " ";
  23. cout << el;
  24.  
  25. }
  26.  
  27. void HV(int i)
  28. {
  29. FOR(j, 1, n)
  30. if (!F[j]){
  31. a[i] = j;
  32. F[j] = 1;
  33. if (i == n) Xl();
  34. else HV(i+1);
  35. F[j] = 0;
  36. }
  37. }
  38.  
  39.  
  40. int main()
  41. {
  42. ios_base::sync_with_stdio(false);
  43. cin.tie(NULL); cout.tie(NULL);
  44. cin >> n;
  45. HV(1);
  46. return 0;
  47. }
  48.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty