-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbiti.cpp
57 lines (47 loc) · 936 Bytes
/
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 <vector>
using namespace std;
unsigned k;
const unsigned n = 2;
void ReadData() {
ifstream in("biti.in");
in >> k;
}
vector<unsigned> a;
vector<unsigned> seq;
void db(unsigned t, unsigned p) {
if(t > k) {
if(k % p == 0) {
for(size_t j = 1; j <= p; ++j) {
seq.push_back(a[j]);
}
}
}
else {
a[t] = a[t - p];
db(t+1,p);
for(size_t j = a[t - p] + 1; j < n; ++j) {
a[t] = j;
db(t+1,t);
}
}
}
void genDeBrujinSeq() {
a.resize(n*k,0);
db(1,1);
}
void printSeq() {
ofstream out("biti.out");
out << seq.size()+ k - 1 << '\n';
for(size_t i = 0, n = seq.size(); i < n; ++i)
out << seq[i];
for(size_t i = 0; i < k-1; ++i)
out << 0;
out << '\n';
}
int main() {
ReadData();
genDeBrujinSeq();
printSeq();
return 0;
}