-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathbiti.cpp
57 lines (52 loc) · 1.04 KB
/
biti.cpp
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 <fstream>
# include <algorithm>
# include <vector>
# include <queue>
# define NR 1100005
using namespace std;
ifstream f("biti.in");
ofstream g("biti.out");
int i,j,n,m,VV,nr,maxx,ok;
int st[NR], ap[1<<21];
queue <int> q;
void back (int k, int niv)
{
if (ok) return;
if (niv==maxx)
{
ok=1;
g<<VV<<"\n";
for (i=1; i<=VV; ++i)
g<<st[i];
g<<"\n";
}
else {
ap[k]=1;
int nr;
nr=k*2; //cu 0
if (nr>=maxx) nr-=maxx;
if (! ap[nr])
{
st[++VV]=0;
back (nr, niv+1);
st[VV]=0; --VV;
}
nr=k*2+1; //cu 1
if (nr>=maxx) nr-=maxx;
if (! ap[nr])
{
st[++VV]=1;
back (nr, niv+1);
st[VV]=0; --VV;
}
ap[k]=0;
}
}
int main ()
{
f>>n;
maxx=(1<<n);
for (i=1; i<=n; ++i) st[++VV]=0;
back (0, 1);
return 0;
}