Posted on 2009-03-27 11:49
superman 阅读(57)
评论(0) 编辑 收藏 引用 所属分类:
USACO
1 #include <iostream>
2
3 using namespace std;
4
5 int main()
6 {
7 freopen("hamming.in", "r", stdin);
8 freopen("hamming.out", "w", stdout);
9
10 int N, B, D, x[64] = { 0 };
11
12 cin >> N >> B >> D;
13
14 x[0] = 0;
15 for (int k = 1; k < N; k++)
16 for (int i = x[k - 1] + 1; i <= (1 << B) - 1; i++)
17 {
18 int j;
19 for (j = 0; j < k; j++)
20 {
21 int cnt = 0, tmp = 1;
22 for (int p = 0; p < B; p++)
23 {
24 if ((i & tmp) != (x[j] & tmp))
25 cnt += 1;
26 tmp *= 2;
27 }
28
29 if (cnt < D)
30 break;
31 }
32
33 if (j == k)
34 {
35 x[k] = i;
36 break;
37 }
38 }
39
40 for (int i = 0; i < N; i++)
41 {
42 cout << x[i];
43 if ((i + 1) % 10 == 0)
44 cout << endl;
45 else
46 {
47 if (i + 1 == N)
48 cout << endl;
49 else
50 cout << ' ';
51 }
52 }
53
54 return 0;
55 }
56