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
相关推荐
论文研究-基于Hamming神经网络的经济效益综合评价模型.pdf, 利用 Hamming神经网络提出了多指标经济效益综合评价模型建模方法 ,并将其应用于企业综合经济效益评价问题的...
FPGA实现扩展的海明校验码,本程序用于冗余存储器的校验
动态规划 Hamming Problem 解题报告
iris recognition code matlab + iris code + code matlab for iris recognition + hamming distance code matlab
这是一篇帮助解决如何做研究的文档,在这篇文档里面,harmming先生讨论了各种与研究有关的事物,值得一看。
以评价DNA编码的基本限制条件之一——Hamming距离为出发点分析了DNA编码的三个参量:码字个数、码字长度与Watson-Crick Hamming距离,并得到它们之间的内在联系;讨论了Watson-Crick Hamming距离与DNA码字重量之间的...
Hamming distance calculating function : ham_dist.m %%%%%%%%%%%-------------------$$$$$$$$>>>>> JITHIN KC <<<< $$$$$$$$-----------------%%%%%%%%%%%%%% @@@如有任何疑问,请联系:
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...
Hamming distance between codewords correlates with semantic similarity. In this paper, we show that the problem of finding a best code for a given dataset is closely related to the problem of graph ...
Tool to measure code distance using Number Geometry
基于视觉词和海明距离优化机制的相似图片检索系统的研究,庄煌,魏翼飞,图片相似检索是通过输入一张查询图,在数据库中基于内容的“语义”,检索出和输入图片相似的图片。本文提出了一种新颖的方法,用于基
通过此代码可以检索利用算法筛选出来的DNA序列是否满足汉明距离、GC含量等约束条件。
SYNTHESIS OF BPSK AND QPSK MODULATIONS IN MATLAB AND QPSK ILUSTRATION WITH HAMMING CODES
Hamming net在入侵检测中的应用,朱莹莹,,入侵检测系统智能性研究是目前网络安全领域的研究热点,人工神经网络(ANN)方法在入侵检测上的应用得到了广泛的关注。本文在分析现�
Monte-Carlo hamming coding sample
串行-并行-UART-with-1-bit Error-Correction-using-Hamming-Code SIPO 和 PISO。 接收器和发射器以及汉明码。 看报告.pdf
线性份分组码的实例,里面有具体的算法和代码实现
该文献的主要思想是:输入文件的哈希值(我用的是文件名)例如一个64位的哈希值,多次随机抽取若干位(例如4位)的值组成一个字串,按照字串值的不同将文件放入不同的哈希桶中。这样一个64位哈希值将被放入64/4=16个...
内容安装$ npm install --save hamming-lsh用法import { Vector , Table } from 'hamming-lsh' ;const t = new Table ( 4 , 2 , 3 ) ;t . add ( new Vector ( [ 1 , 0 , 1 , 1 ] ) ) ;t . add ( new Vector ( [ 0 , ...
by the Hamming distance between their respective binary codes. By using two loss functions measuring the degree of divergence between the training and predicted ratings, we formulate the problem of ...