The Hamming distance between two strings of bits (binary integers) is the number of corresponding bit positions that differ. This can be found by using XOR on corresponding bits or equivalently, by adding corresponding bits (base 2) without a carry. For example, in the two bit strings that follow:
A 0 1 0 0 1 0 1 0 0 0 B 1 1 0 1 0 1 0 1 0 0 A XOR B = 1 0 0 1 1 1 1 1 0 0
The Hamming distance (H) between these 10-bit strings is 6, the number of 1's in the XOR string.
Input
Input consists of several datasets. The first line of the input contains the number of datasets, and it's followed by a blank line. Each dataset contains N, the length of the bit strings and H, the Hamming distance, on the same line. There is a blank line between test cases.
Output
For each dataset print a list of all possible bit strings of length N that are Hamming distance H from the bit string containing all 0's (origin). That is, all bit strings of length N with exactly H 1's printed in ascending lexicographical order.
The number of such bit strings is equal to the combinatorial symbol C(N,H). This is the number of possible combinations of N-H zeros and H ones. It is equal to
This number can be very large. The program should work for .
Print a blank line between datasets.
Sample Input
1 4 2
Sample Output
0011 0101 0110 1001 1010 1100
最后输出只能有一行空行,否则WA
#define RUN #ifdef RUN #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <string> #include <iostream> #include <sstream> #include <map> #include <set> #include <vector> #include <list> #include <cctype> #include <algorithm> #include <utility> #include <math.h> #include <ctime> using namespace std; #define MAXN 20 char buf[MAXN]; int N, H; int len; int main(){ #ifndef ONLINE_JUDGE freopen("729.in", "r", stdin); freopen("out.out", "w", stdout); #endif int n; scanf("%d", &n); while(n--){ scanf("%d%d", &N, &H); len = 0; //N-H zeros and H ones memset(buf, 0, sizeof(buf)); for(int i=0; i<N-H; i++){ buf[len++] = '0'; } for(int i=0; i<H; i++){ buf[len++] = '1'; } do { printf("%s\n", buf); } while ( next_permutation(buf, buf+len) ); if(n != 0){ printf("\n"); } } } #endif
相关推荐
c语言入门 c语言_leetcode题解461-hamming-distance.c
java java_leetcode题解之Hamming Distance.java
FPGA实现扩展的海明校验码,本程序用于冗余存储器的校验
在"Hamming Problem"这个编程挑战中,我们需要找到一个特定的Hamming序列中的第i个数。Hamming序列是由三个质数p1, p2, 和 p3定义的,序列包含所有只被这三个质数之一整除的自然数,按递增顺序排列。 例如,给定...
iris recognition code matlab + iris code + code matlab for iris recognition + hamming distance code matlab
这个压缩包文件"检验代码_Hammingdistance_GCcontent_DNA_"显然包含了用于检查DNA序列特定属性的程序,具体来说,就是汉明距离(Hamming Distance)和GC含量。下面将详细介绍这两个概念及其在DNA分析中的应用。 **...
Hamming)先生在贝尔通讯研究(Bell Communications Research)研讨会上的演讲,题为《你和你的研究》。哈明先生当时是加州蒙特雷海军研究生院的教授,并且是贝尔实验室的退休科学家。演讲于1986年3月7日在贝尔实验...
以评价DNA编码的基本限制条件之一——Hamming距离为出发点分析了DNA编码的三个参量:码字个数、码字长度与Watson-Crick Hamming距离,并得到它们之间的内在联系;讨论了Watson-Crick Hamming距离与DNA码字重量之间的...
Hamming distance calculating function : ham_dist.m %%%%%%%%%%%-------------------$$$$$$$$>>>>> JITHIN KC <<<< $$$$$$$$-----------------%%%%%%%%%%%%%% @@@如有任何疑问,请联系:
标题“通信仿真-hamming码编码译码器”表明我们要讨论的是一个用于通信领域的仿真工具,具体来说是关于Hamming码的编码和译码过程。Hamming码是一种纠错编码技术,它在数据传输或存储中用于检测和纠正单个比特错误,...
Semantic hashing seeks compact binary codes of data-points so that the Hamming distance between codewords correlates with semantic similarity. In this paper, we show that the problem of finding a best...
"基于PCM-Hamming码的FSK调制解调系统1" 一、PCM编解码技术 PCM(Pulse Code Modulation,脉冲编码调制)是一种数字通信中的编码方式,主要是将语音、图像等模拟信号每隔一定时间进行取样,时期离散化,再将抽样值...
Tool to measure code distance using Number Geometry
SYNTHESIS OF BPSK AND QPSK MODULATIONS IN MATLAB AND QPSK ILUSTRATION WITH HAMMING CODES
文章的重点是构建一种对抗性强的属性保留哈希函数,用于处理汉明距离(Hamming Distance)谓词。汉明距离衡量的是两个字符串在对应位置上不同字符的数量。该哈希函数可以区分汉明距离至少达到某个阈值t的输入与距离...
Hamming net在入侵检测中的应用,朱莹莹,,入侵检测系统智能性研究是目前网络安全领域的研究热点,人工神经网络(ANN)方法在入侵检测上的应用得到了广泛的关注。本文在分析现�
Monte-Carlo hamming coding sample