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;
}



 

posted @ 2014-08-16 16:18  颜威  阅读(120)  评论(0编辑  收藏  举报