USACO Hamming Codes

时间:2022-04-29 14:24:50

题目大意:求n个两两hamming距离大于等于d的序列,每个元素是一个b bit的数

思路:仍然暴力大法好

 /*{
ID:a4298442
PROB:hamming
LANG:C++
}
*/
#include<iostream>
#include<fstream>
#define maxn 500
using namespace std;
ifstream fin("hamming.in");
ofstream fout("hamming.out");
//#define fin cin
//#define fout cout
int hamming(int x,int y,int b)
{
int ans=;
for(int i=;i<=b;i++)
{
int u=x&,v=y&;
if(u!=v)ans++;
x>>=;y>>=;
}
return ans;
}
int ans[maxn];
int main()
{
int n,b,d;
fin>>n>>b>>d;
for(int idx=;idx<=n;idx++)
{
for(int i=;i<=<<(b+)-;i++)
{
int flag=;
for(int j=;j<idx;j++)
{
if(hamming(ans[j],i,b)<d){flag=;break;}
}
if(!flag)
{
ans[idx]=i;break;
}
}
}
for(int i=;i<n;i++)
{
fout<<ans[i];
if(i%==)fout<<endl;else fout<<" ";
}
fout<<ans[n]<<endl;
return ;
}