-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1020.cpp
More file actions
68 lines (66 loc) · 1.57 KB
/
1020.cpp
File metadata and controls
68 lines (66 loc) · 1.57 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
64
65
66
67
68
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
struct IV {
int c = 0;
vector<int> v;
};
const int _N = 32;
int n;
IV f(int st, vector<int>& now) {
IV r;
if (st < n) {
int k = 0;
while (st % (now[k] + now[k + 1]) != 0 && k + 1 < (int)now.size()) k++;
if (k == (int)now.size() - 1) return r;
vector<int> now1;
now1.assign(now.begin(), now.end());
now1.insert(now1.begin() + k + 1, st);
IV r1 = f(st + 1, now1);
r.c += r1.c;
r.v = r1.v;
for (int i = k + 1; i < (int)now.size() - 1; i++) {
if (st % (now[i] + now[i + 1]) != 0) continue;
vector<int> now2;
now2.assign(now.begin(), now.end());
now2.insert(now2.begin() + i + 1, st);
IV r2 = f(st + 1, now2);
r.c += r2.c;
if (r2.v > r.v) r.v = r2.v;
}
} else {
int k = 0;
while (st % (now[k] + now[k + 1]) != 0 && k + 1 < (int)now.size()) k++;
if (k == (int)now.size() - 1) return r;
vector<int> now1;
now1.assign(now.begin(), now.end());
now1.insert(now1.begin() + k + 1, st);
r.c++;
r.v = now1;
for (int i = k + 1; i < (int)now.size() - 1; i++) {
if (st % (now[i] + now[i + 1]) == 0) {
r.c++;
}
}
}
return r;
}
main(void) {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n;
if (n == 1) {
cout << "1\n0 1\n";
return 0;
}
vector<int> tmp = {0, 1};
IV res = f(2, tmp);
if (res.c == 0) {
cout << 0;
return 0;
}
cout << res.c << '\n';
cout << res.v[0];
for (int i = 1; i < (int)res.v.size(); i++) cout << " " << res.v[i];
return 0;
}