/*
ID: cm750621
PROG: hamming
LANG: C++
*/
#include <cstdio>
#include <cstdlib>
int N,B,D,can[300],i,j,k,m,n,begin=0,end=1,length;
int in(int a,int b){
int i,s=0;
for(i=0;i<B;i++)
if(((a>>i)&1)!=((b>>i)&1))
s++;
if(s>=D)
return 1;
return 0;
}
int main(){
freopen("hamming.in","r",stdin);
freopen("hamming.out","w",stdout);
scanf("%d%d%d",&N,&B,&D);
for(i=1;i<=B;i++)
end*=2;
end--;
for(i=1;i<=end;i++)
can[i]=i;
while(end>begin){
length=0;
for(i=begin;i<=end;i++){
if(!in(can[i],can[begin]))
continue;
else
can[begin+1+length++]=can[i];
}
begin++;
end=begin+length;
}
printf("%d",can[0]);
for(i=1;i<N;i++)
{
if(!((i)%10))
printf("\n");
else
printf(" ");
printf("%d",can[i]);
}
puts("");
return 0;
}
usaco 2.1.5 hamming
最新推荐文章于 2023-04-19 22:21:27 发布