new file: 0x10/3.cpp
This commit is contained in:
+37
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user