-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmz11-1.cpp
More file actions
63 lines (51 loc) · 1.22 KB
/
mz11-1.cpp
File metadata and controls
63 lines (51 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <vector>
#include <algorithm>
std::vector<std::string> ans;
void gen_b(std::string &alp, std::string &s, int l, int k, int len)
{
if (l == k) {
std::string out;
for (int i = 0; i < len - k; i++) {
out.push_back(alp[i]);
}
for (int i = 0; i < len - k; i++) {
out.push_back(alp[len - k - i - 1]);
}
for (int i = 0; i < k; i++) {
out.push_back(s[i]);
}
for (int i = 0; i < k; i++) {
out.push_back(s[k - i - 1]);
}
ans.push_back(out);
return;
}
s[l] = '1';
gen_b(alp, s, l + 1, k, len);
s[l] = '2';
gen_b(alp, s, l + 1, k, len);
}
void gen_a(std::string &s, std::string &bet, int l, int k, int len)
{
if (l == k) {
gen_b(s, bet, 0, len - k, len);
return;
}
gen_b(s, bet, 0, len - l, len);
s[l] = '3';
gen_a(s, bet, l + 1, k, len);
s[l] = '4';
gen_a(s, bet, l + 1, k, len);
}
int main()
{
int k;
std::cin >> k;
std::string alp(k / 2, ' '), bet(k / 2, ' ');
gen_a(alp, bet, 0, k / 2, k / 2);
std::sort(ans.begin(), ans.end());
for (auto c : ans) {
std::cout << c << "\n";
}
}