-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hamming Codes_Bits.cpp
98 lines (89 loc) · 1.88 KB
/
Hamming Codes_Bits.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
ID: zdzapple
LANG: C++
TASK: hamming
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <climits>
#include <fstream>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
using namespace std;
const string input_file = "hamming.in";
const string out_file = "hamming.out";
ifstream fin;
ofstream fout;
void openfile() { fin.open(input_file.c_str()); fout.open(out_file.c_str()); }
void closefile() { fin.close(), fout.close(); }
int i, j, k, N, B, D, maxval;
const int MAX = (1 << 8 + 1);
const int NMAX = 65;
const int BMAX = 10;
const int DMAX = 10;
int nums[NMAX], dist[MAX][MAX];
void findGroups(int cur, int start)
{
if (cur == N) {
for (i = 0; i < cur; ++ i)
{
if (i % 10)
fout << " ";
fout << nums[i];
if (i % 10 == 9 || i == cur - 1)
fout << endl;
}
exit(0);
}
int canuse;
for (i = start; i < maxval; ++ i)
{
canuse = 1;
for (j = 0; j < cur; ++ j)
{
if (dist[nums[j]][i] < D) {
canuse = 0;
break;
}
}
if (canuse) {
nums[cur] = i;
findGroups(cur + 1, i + 1);
}
}
}
void solve()
{
fin >> N >> B >> D;
maxval = (1 << B);
for (i = 0; i < maxval; ++ i)
{
for (j = 0; j < maxval; ++ j)
{
int num = i ^ j;
dist[i][j] = 0;
while (num != 0)
{
if (num & 0x01)
dist[i][j] ++;
num >>= 1;
}
}
}
nums[0] = 0;
findGroups(1, 1);
}
int main()
{
openfile();
solve();
closefile();
return 0;
}