Advertisement
tuki2501

phanhoach.cpp

Sep 3rd, 2022
1,071
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 15;
  5.  
  6. int n, preMax[N];
  7. vector<int> a[N];
  8.  
  9. void print() {
  10.     cout << "{";
  11.     for (int i = 1; i <= n; i++) {
  12.         for (int j = 0; j < a[i].size(); j++) {
  13.             cout << a[i][j];
  14.             if (j + 1 < a[i].size()) {
  15.                 cout << ", ";
  16.             }
  17.         }
  18.         if (a[i + 1].size()) cout << "}, {";
  19.     }
  20.     cout << "}\n";
  21. }
  22.  
  23. void brute(int i) {
  24.     for (int j = 1; j <= preMax[i - 1] + 1; j++) {
  25.         preMax[i] = max(preMax[i - 1], j);
  26.         a[j].push_back(i);
  27.         if (i < n) brute(i + 1);
  28.         else print();
  29.         a[j].pop_back();
  30.     }
  31. }
  32.  
  33. int main() {
  34.     n = 3;
  35.     brute(1);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement