-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP2063.cpp
More file actions
59 lines (53 loc) · 1.17 KB
/
P2063.cpp
File metadata and controls
59 lines (53 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100]={0};
vector<int> ans;
vector<int> anss;
stack<int> t;
void dfs(int x){
if(!t.empty()){
ans.push_back(t.top());
if(ans.size() == n){
int t=0;
for(int i = 0;i < ans.size(); i++)
t=t*10+ans[i];
anss.push_back(t);
}
t.pop();
dfs(x);
t.push(ans.back());
ans.pop_back();
}
if(x<n){
t.push(a[x]);
dfs(x+1);
t.pop();
}
}
signed main(){
while(scanf("%d",&n)!=EOF){
while(!t.empty()) t.pop();
ans.clear();
anss.clear();
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
// sort(a,a+n);
// printf("here\n");
dfs(0);
sort(anss.begin(),anss.end());
for(int i=0;i < anss.size();i++){
ans.clear();
while(anss[i]){
ans.push_back(anss[i]%10);
anss[i]/=10;
}
for(int i=ans.size()-1;i>=0;i--)
printf("%d ",ans[i]);
printf("\n");
}
// printf("here\n");
}
return 0;
}