UVa-729-The Hamming Distance Problem
AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 3. Brute Force :: Elementary Skills
// 729 - The Hamming Distance Problem #include <iostream> #include <algorithm> #include <cstring> using namespace std; int main(void) { int i, j, t, n, h; int a[20]; while(cin >> t) { while(t--) { cin >> n >> h; memset(a, 0, sizeof(a)); for(i=0; i<h; i++) a[n-1-i] = 1; do{ for(j=0; j<n; j++) cout << a[j]; cout << endl; }while(next_permutation(a, a+n)); if(t != 0) cout << endl; } } return 0; }