729 - The Hamming Distance Problem

#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
	//freopen("data.in","r",stdin);
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int h,n;
		scanf("%d %d",&h,&n);
		char str[20];
		int i;
		for(i=0;i<h-n;i++)
			str[i]='0';
		for(;i<h;i++)
			str[i]='1';
		str[i]=0;
		do
		{
			printf("%s\n",str);
		}while(next_permutation(str,str+i));
		if(T)
			printf("\n");
	}
	return 0;
}


你可能感兴趣的:(729 - The Hamming Distance Problem)