UVa 729 The Hamming Distance Problem:全排列输出及小细节

729 - The Hamming Distance Problem

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=670

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

加空字符啊。。。

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索number
, of
, The
, strings
, BETWEEN
BIT
hamming distance、hamming distance公式、hammingdistance、hamming distance c、hammingdistance c,以便于您获取更多的相关知识。

时间: 2024-12-02 13:55:59

UVa 729 The Hamming Distance Problem:全排列输出及小细节的相关文章

JS实现的数组全排列输出算法

 这篇文章主要介绍了JS实现的数组全排列输出算法,实例分析了全排列的原理与相关的javascript实现技巧,具有一定参考借鉴价值,需要的朋友可以参考下     本文实例讲述了JS实现的数组全排列输出算法.分享给大家供大家参考.具体分析如下: 这段js代码对数组进行全排列输出,改进了一些老的代码 从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n个不同元素中取出m个元素的一个排列.当m=n时所有的排列情况叫全排列. ? 1 2 3 4 5 6 7 8 9 10 11 12

python回溯法实现数组全排列输出实例分析_python

本文实例讲述了python回溯法实现数组全排列输出的方法.分享给大家供大家参考.具体分析如下: 全排列解释:从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n个不同元素中取出m个元素的一个排列.当m=n时所有的排列情况叫全排列. from sys import stdout #code from http://www.jb51.net/ def perm(li, start, end): if(start == end): for elem in li: stdout.wr

《C语言解惑》—— 2.1 printf输出的小奥妙

2.1 printf输出的小奥妙 需要注意printf输出字符串时,"\n"之前和之后的空格含义不同,前面的空格没有影响,即如下两条语句 printf ("Hardness=%d \n",2); printf ("Hardness=%d\n ",2); 的输出是对齐的.而下面两条语句 printf ("Hardness=%d\n ",2); printf ("Hardness=%d\n ",2); 的输出是

UVa 216 Getting in Line:全排列&枚举

216 - Getting in Line Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=152 Computer networking requires that the computers in the network be linked. This problem considers

UVa 10026:Shoemaker's Problem

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=967 类型: 贪心 原题: Shoemaker has N jobs (orders from customers) which he must make. Shoemaker can work on only one job in each day.

IIUC ONLINE CONTEST 2008 / UVa 11389 The Bus Driver Problem:贪心

11389 - The Bus Driver Problem Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2384 In a city there are n bus drivers. Also there are n morning bus routes

UVa 11507 Bender B. Rodríguez Problem:模拟&异或

11507 - Bender B. Rodríguez Problem Time limit: 4.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2502 Bender is a robot built by Mom's Friendly Robot Company at its pl

uva 10245 - The Closest Pair Problem

点击打开链接uva 10245 题目意思:   给定N个点,找到所有点中距离最小的 解题思路: 1:递归+分治 <网上大牛的解释如下> 2在二维空间里,可用分治法求解最近点对问题.预处理:分别根据点的x轴和y轴坐标进行排序,得到X和Y,很显然此时X和Y中的点就是S中的点.            1情况(1):点数小于等于三时:                                  2情况(2):点数大于三时:            3首先划分集合S为SL和SR,使得SL中的每一个点

uva 100 The 3n+1 problem

题目链接: http://www.programming-challenges.com/pg.php?page=studenthome /* The 3n+1 problem 计算每个数的循环节长度,求给定区间的循环节长度的最大值. */ #include<iostream> #include<stdio.h> using namespace std; int jk(int n) { int num=1; while(n!=1) { if(n&1) n+=(n<<