The topic is simple, find the n binary length is B, and 22 between the bits at least D bit different
The brute force enumeration is good.
/*id:modengd1prog:hamminglang:c++*/#include <iostream> #include <stdio.h> #include <memory.h> Using namespace Std;int sta[64];bool slove (int sta[64],int n,int b,int d,int deep) {if (deep==n) {bool Isbegi N=true; for (int i=0;i<n;i++) {if (isbegin) {cout<<sta[i]; Isbegin=false; } else cout<< ' <<sta[i]; if ((i%10) ==9)//Every 10 digits of the line {isbegin=true; cout<<endl; }} if ((N%10))//check if you need to output line breaks in the last line cout<<endl; return true; } for (int i=0;i< (1<<B); i++) {bool allok=true; Sta[deep]=i; for (int j=0;j<deep;j++) {int dif=i^sta[j]; int counter=0; while (dif>0) {dif-=dif&-dif; counter++; } if (counter<D)//Hamming distance less than D on break {allok=false; Break }} if (Allok&&slove (sta,n,b,d,deep+1))//and the Hamming distance of the previously obtained number is sufficient, then enumerate the next return true; } return false;} int main () {freopen ("hamming.in", "R", stdin); Freopen ("Hamming.out", "w", stdout); int n,b,d; int sta[64]; scanf ("%d%d%d", &n,&b,&d); Slove (sta,n,b,d,0); return 0;}
Usaco Hamming Codes