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 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 containsN,
the length of the bit strings andH, the Hamming distance, on the same line. There is a blank line between test cases.
For each dataset print a list of all possible bit strings of lengthNthat are Hamming distanceHfrom
the bit string containing all 0's (origin). That is, all bit strings of lengthNwith exactlyH1's
printed in ascending lexicographical order.
The number of such bit strings is equal to the combinatorial symbolC(N,H). This is the number of possible combinations ofN-Hzeros andHones. It is equal to
This number can be very large. The program should work for.
Print a blank line between datasets.
1
4 2
0011
0101
0110
1001
1010
1100
给出两个数,一个是总位数,另一个是1的位数,求全排列
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
int n,k;
cin>>n;
for(k=1;k<=n;k++)
{
int r,t,i,j;
cin>>r>>t;
string str;
for(i=1;i<=r-t;i++)
str=str+'0';
for(i;i<=r;i++)
str=str+'1';
cout<<str<<endl;
while(next_permutation(str.begin(), str.end()))
{
cout<<str<<endl;
}
if(k!=n) cout<<endl;
}
return 0;
}
分享到:
相关推荐
动态规划 Hamming Problem 解题报告
iris recognition code matlab + iris code + code matlab for iris recognition + hamming distance code matlab
Tool to measure code distance using Number Geometry
通过此代码可以检索利用算法筛选出来的DNA序列是否满足汉明距离、GC含量等约束条件。
基于视觉词和海明距离优化机制的相似图片检索系统的研究,庄煌,魏翼飞,图片相似检索是通过输入一张查询图,在数据库中基于内容的“语义”,检索出和输入图片相似的图片。本文提出了一种新颖的方法,用于基
该文献的主要思想是:输入文件的哈希值(我用的是文件名)例如一个64位的哈希值,多次随机抽取若干位(例如4位)的值组成一个字串,按照字串值的不同将文件放入不同的哈希桶中。这样一个64位哈希值将被放入64/4=16个...
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...
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 ...
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 ...
We also study two examples of common leakage models: the Hamming weight and the Hamming distance models. For instance, the study in the case of the Hamming weight model gives that the probability of ...
leetcode添加元素使和等于 LeetCodeOne 461. Hamming Distance The Hamming distance between two ...hammingDistance(int x, int y) { int dist = 0; int n = x^y; //异或 while(n) { ++dist; n = n
verilog 实现的hamming码生成,用于fpga
hamming code in matlab
cpu(Hamming码)
Hamming distance, Hamming spheres and error correcting capability
For implementing the Hamming coding in verilog or VHDL
74Hamming code in Gaussian channel
Hamming法求级数,级数,x取值点,误差范围皆在程序中指定,C语言
hamming 级数求和 精度可以控制 比较暴力 高精度需要考虑n溢出问题