내의 모든 비트 시퀀스를 생성한다.최대 입력 파라미터 <code>t</code>까지 거리 2 <em>다음</em>, <code>v</code>와 해밍 거리가 1이 비트의 컬렉션을 계산 비트 <code>v</code>의 벡터 주어 해밍 거리 t
그래서
011 I should get
~~~
111
001
010
~~~ -> 3 choose 1 in number
101
000
110
~~~ -> 3 choose 2
100
~~~ -> 3 choose 3
얼마나 효율적으로이를 계산하기? 벡터는 항상 차원 3이 아닙니다 (예 : 그것은 6 일 수 있습니다. 이것은 실제 코드에서 많은 시간을 수행 할 것이기 때문에 (심지어 더 많은 메모리를 지불하는 것만으로도) 어떤 효율성도 환영 할 것입니다.
내 시도 :
#include <iostream>
#include <vector>
void print(const std::vector<char>& v, const int idx, const char new_bit)
{
for(size_t i = 0; i < v.size(); ++i)
if(i != idx)
std::cout << (int)v[i] << " ";
else
std::cout << (int)new_bit << " ";
std::cout << std::endl;
}
void find_near_hamming_dist(const std::vector<char>& v, const int t)
{
// if t == 1
for(size_t i = 0; i < v.size(); ++i)
{
print(v, i, v[i]^1);
}
// I would like to produce t == 2
// only after ALL the t == 1 results are reported
/* how to? */
}
int main()
{
std::vector<char> v = {0, 1, 1};
find_near_hamming_dist(v, 1);
return 0;
}
출력 :
MacBook-Pro:hammingDist gsamaras$ g++ -Wall -std=c++0x hammingDist.cpp -o ham
MacBook-Pro:hammingDist gsamaras$ ./ham
1 1 1
0 0 1
0 1 0
나는 [최근] (http://stackoverflow.com/q/40768507/555045) 이미 질문에 대해 다르게 공식화했지만이 답변을 제공합니다. – harold
@harold 그래, 약간 다르니까! :) – gsamaras