Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 15;
- int n, preMax[N];
- vector<int> a[N];
- void print() {
- cout << "{";
- for (int i = 1; i <= n; i++) {
- for (int j = 0; j < a[i].size(); j++) {
- cout << a[i][j];
- if (j + 1 < a[i].size()) {
- cout << ", ";
- }
- }
- if (a[i + 1].size()) cout << "}, {";
- }
- cout << "}\n";
- }
- void brute(int i) {
- for (int j = 1; j <= preMax[i - 1] + 1; j++) {
- preMax[i] = max(preMax[i - 1], j);
- a[j].push_back(i);
- if (i < n) brute(i + 1);
- else print();
- a[j].pop_back();
- }
- }
- int main() {
- n = 3;
- brute(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement