UVa 729 the Hamming Distance Problem: Full array output and small details

Source: Internet
Author: User

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 Diffe R. This can is found by using XOR on corresponding bits or equivalently and by adding corresponding bits (base 2) without a C Arry. 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

The Hamming distance (H) between these 10-bit strings are 6, the number of 1 ' s in the XOR string.

Input

Input consists of several datasets. The "a" of the input contains the number of datasets, and it's followed by a blank line. Each dataset is 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 so are Hamming distance H from the bit string cont Aining all 0 ' s (Origin). This is, the all bit strings of the 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

Add empty characters Ah ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.