#include <iostream>
#include <vector>
#include <string>
using namespace std;
void generateSequences(string current, int openRound, int closeRound, int openSquare, int closeSquare, vector<string> &result) {
if (openRound == 0 && closeRound == 0 && openSquare == 0 && closeSquare == 0) {
result.push_back(current);
return;
}
if (openRound > 0)
generateSequences(current + '(', openRound - 1, closeRound, openSquare, closeSquare, result);
if (closeRound > openRound)
generateSequences(current + ')', openRound, closeRound - 1, openSquare, closeSquare, result);
if (openSquare > 0)
generateSequences(current + '[', openRound, closeRound, openSquare - 1, closeSquare, result);
if (closeSquare > openSquare)
generateSequences(current + ']', openRound, closeRound, openSquare, closeSquare - 1, result);
}
vector<string> generateValidSequences(int n) {
vector<string> result;
if (n % 2 != 0) {
return result;
}
generateSequences("", n / 2, n / 2, n / 2, n / 2, result);
return result;
}
int main() {
int n;
cin >> n;
vector<string> validSequences = generateValidSequences(n);
for (const string &seq : validSequences) {
cout << seq << endl;
}
return 0;
}
Входные данные
4
Результат работы
(())
([])
()()
()[]
[()]
[[]]
[]()
[][]