fork download
  1. /**********************************************************************************************
  2. -> @author : a_e_kasem
  3. -> "Code is an art — let logic be your ink and syntax your rhythm."
  4. ***********************************************************************************************/
  5. //*------------------------------------------------------------------------------------------*//
  6. // ﷽
  7. // { وَأَنْ لَيْسَ لِلْإِنْسَانِ إِلَّا مَا سَعَى }
  8. //
  9. // فَالجُهدُ يُثمِرُ إنْ تَضافَرَ صَفوُهُ، والعَزمُ يَرفعُ صَرحَ كُلِّ بُنيانِ
  10. //
  11. // وَما نَيلُ المَطالِبِ بِالتَمَنّي
  12. // وَلَكِن تُؤخَذُ الدُنيا غِلابا
  13. // ***
  14. // وَما اِستَعصى عَلى قَومٍ مَنالٌ
  15. // إِذا الإِقدامُ كانَ لَهُم رِكابا
  16. //*------------------------------------------------------------------------------------------*//
  17.  
  18.  
  19. #include <bits/stdc++.h>
  20.  
  21. using namespace std;
  22.  
  23. #define int long long
  24. #define cinAll(a) for (auto &it : a) cin >> it
  25. #define all(x) (x).begin(), (x).end()
  26. #define rall(x) (x).rbegin(), (x).rend()
  27. #define NO void(cout << "NO\n")
  28. #define YES void(cout << "YES\n")
  29. #define endl "\n"
  30. const int INF = 1e18;
  31. const int MOD = 998244353;
  32. const int MAXN = 2e5 + 5;
  33.  
  34.  
  35. int n;
  36. vector<int> a, path;
  37. vector<vector<int>> ans;
  38.  
  39. void go(int i){
  40. if (i == n)
  41. {
  42. ans.push_back(path);
  43. return;
  44. }
  45.  
  46. path.push_back(a[i]);
  47. go(i+1);
  48. path.pop_back();
  49. go(i+1);
  50. }
  51.  
  52. void solve()
  53. {
  54. cin >> n;
  55. a.resize(n);
  56. for (int i = 0; i < n; i++)
  57. cin >> a[i];
  58.  
  59. go(0);
  60. sort(ans.begin(), ans.end());
  61. for (int i = 0; i < ans.size(); i++)
  62. {
  63. for (int j = 0; j < ans[i].size(); j++)
  64. {
  65. cout << ans[i][j] << " ";
  66. }
  67. cout << endl;
  68. }
  69. }
  70.  
  71.  
  72. void FastIO();
  73.  
  74. int32_t main()
  75. {
  76. FastIO();
  77. int t = 1;
  78. // cin >> t;
  79. while (t--)
  80. solve();
  81.  
  82. return 0;
  83. }
  84.  
  85. void FastIO()
  86. {
  87. ios::sync_with_stdio(false);
  88. cin.tie(nullptr);
  89. cout.tie(nullptr);
  90. }
  91.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout