-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1038.cpp
More file actions
57 lines (55 loc) · 994 Bytes
/
1038.cpp
File metadata and controls
57 lines (55 loc) · 994 Bytes
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
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
bool flag=false;
bool start= false;
int d[11];
int n;
long long expressNum(){
long long tmp=0;
for(int i=0;i<11;i++){
tmp*=10;
tmp+=d[i];
}
return tmp;
}
void go(int digit){
if(digit>10){
if(n==0)
flag=true;
n--;
return ;
}
if(start){
for(int i=0;i<10;i++){
if(d[digit-1]>i){
d[digit]=i;
go(digit+1);
if(flag)return ;
d[digit]=0;
}
}
}else{
d[digit]=0;
go(digit+1);
if(flag)return ;
for(int i=1;i<10;i++){
start=true;
d[digit]=i;
go(digit+1);
if(flag)return ;
d[digit]=0;
start=false;
}
}
}
int main(){
cin>>n;
if(n>1022){
cout<<"-1";
return 0;
}
go(0);
cout<<expressNum();
}