new file: 0x10/3.cpp

This commit is contained in:
hanyixuanten
2026-08-24 20:06:11 +08:00
parent daa97afaae
commit eb7a278b1b
+37
View File
@@ -0,0 +1,37 @@
// 129
#include <bits/stdc++.h>
using namespace std;
vector<int> 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;
}