You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
964 B
52 lines
964 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
int n;
|
|
const int N = 20;
|
|
int a[N], al;
|
|
string b[100010];
|
|
int bl;
|
|
char str[10];
|
|
|
|
void dfs(int u) {
|
|
if (u == n + 1) {
|
|
string s = "";
|
|
for (int i = 1; i <= al; i++) {
|
|
sprintf(str, "%02d", a[i]);
|
|
string str2 = str;
|
|
s += str2 + " ";
|
|
}
|
|
|
|
b[++bl] = s;
|
|
return;
|
|
}
|
|
|
|
a[++al] = u;
|
|
dfs(u + 1);
|
|
al--;
|
|
|
|
dfs(u + 1);
|
|
}
|
|
|
|
void print(string s) {
|
|
for (int i = 0; i < s.size(); i++) {
|
|
if (i == 0 && s[i] == '0')
|
|
continue;
|
|
if (s[i] == ' ' && s[i + 1] == '0') {
|
|
i++;
|
|
cout << " ";
|
|
continue;
|
|
}
|
|
cout << s[i];
|
|
}
|
|
cout << endl;
|
|
}
|
|
|
|
int main() {
|
|
// freopen("1.out", "w", stdout);
|
|
cin >> n;
|
|
dfs(1);
|
|
sort(b + 1, b + 1 + bl);
|
|
for (int i = 1; i <= bl; i++)
|
|
print(b[i]);
|
|
return 0;
|
|
} |