トピックポータル
https://lydsy.com/JudgeOnline/problem.php?id=3033
問題の解決策
まず、直感によると、最初の質問への答えは、しなければならない(2 ^ k個\)\、つまり、長さのすべての\(k個\)バイナリ文字列。(証明にはなりません
その後の長さ\(2 ^ {K-1 } \) 点として数、最後のものは、最後の後、最後の接続された一方に接続され、エッジの重みである\(K-1 \)ビット。
そして、ついにその答えはオイラー図のものでなければなりません。辞書的に最小限のを確実にするためには、そのすべての優先とる\(0 \) 、そして行く\(1 \を)。
時間複雑\(O(N \ N-ログ)\) 。
#include<bits/stdc++.h>
#define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define fi first
#define se second
#define pb push_back
template<typename A, typename B> inline char smax(A &a, const B &b) {return a < b ? a = b, 1 : 0;}
template<typename A, typename B> inline char smin(A &a, const B &b) {return b < a ? a = b, 1 : 0;}
typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii;
template<typename I> inline void read(I &x) {
int f = 0, c;
while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
x = c & 15;
while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
f ? x = -x : 0;
}
const int K = 11 + 2;
const int N = (1 << 11) + 7;
int n, k, cnt;
char ans[N];
bool vis[N << 1];
struct Edge { int to, ne; } g[N << 1]; int head[N], tot;
inline void addedge(int x, int y) { g[++tot].to = y, g[tot].ne = head[x], head[x] = tot; }
inline void adde(int x, int y) { addedge(x, y), addedge(y, x); }
inline void dfs(int x) {
for fec(i, x, y) if (!vis[i]) {
vis[i] = 1;
dfs(y);
}
ans[++cnt] = x;
}
inline void work() {
for (int i = 0; i <= (n >> 1); ++i) addedge(i, (n >> 1) & ((i << 1) | 1)), addedge(i, (n >> 1) & (i << 1));
dfs(0);
// dbg("cnt = %d\n", cnt);
printf("%d ", n + 1);
--cnt;
for (int i = 0; i < k; ++i) putchar('0' + ((ans[cnt] >> i) & 1));
--cnt;
while (cnt >= k) putchar('0' + (ans[cnt--] & 1));
puts("");
}
inline void init() {
read(k);
n = (1 << k) - 1;
}
int main() {
#ifdef hzhkk
freopen("hkk.in", "r", stdin);
#endif
init();
work();
fclose(stdin), fclose(stdout);
return 0;
}