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 Output
For each dataset print a list of all possible bit strings of length
The number of such bit strings is equal to the combinatorial symbol
This number can be very large. The program should work for .
Print a blank line between datasets.
1 4 2
Sample Output
0011 0101 0110 1001 1010 1100
全排列的题。但是别忘了,要从最小的开始全排列。例如00001111,000111.#include<iostream> #include<stdio.h> #include<string> #include<algorithm> using namespace std; int main() { int t; scanf("%d",&t); while(t--) { int m,n; int a[20]; scanf("%d%d",&m,&n); for(int i=0;i<m;i++) { if(i<m-n) a[i]=0; else a[i]=1; } do { for(int i=0;i<m;i++) printf("%d",a[i]); printf("\n"); }while(next_permutation(a,a+m)); if(t) printf("\n"); } return 0; }