From eb7a278b1b6daa092d5641543982d1a02d43f188 Mon Sep 17 00:00:00 2001 From: hanyixuanten <105723997+hanyixuanten@users.noreply.github.com> Date: Mon, 24 Aug 2026 20:06:11 +0800 Subject: [PATCH] new file: 0x10/3.cpp --- 0x10/3.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 0x10/3.cpp diff --git a/0x10/3.cpp b/0x10/3.cpp new file mode 100644 index 0000000..d798b18 --- /dev/null +++ b/0x10/3.cpp @@ -0,0 +1,37 @@ +// 129 +#include +using namespace std; +vector ans; +int stk[25], tot, n, cnt; +void dfs(int now) +{ + if (cnt >= 20) + return; + if (now > n) + { + cnt++; + for (auto x : ans) + cout << x; + for (int i = tot - 1; i >= 0; i--) + cout << stk[i]; + puts(""); + return; + } + if (tot) + { + ans.push_back(stk[--tot]); + dfs(now); + stk[tot++] = ans.back(); + ans.pop_back(); + } + stk[tot++] = now; + dfs(now + 1); + tot--; +} + +int main() +{ + cin >> n; + dfs(1); + return 0; +} \ No newline at end of file