注意://num[cur] returns to original,so as not to disturb further search
num[cur]=0;
#include<stdio.h>
#include<string.h>
int hmax;
int len;
void permutation(int cur,int ham,int* num)
{
if(cur == len && ham != hmax) return;
if(ham == hmax)
{
for(int i = 0; i < len;i++)
{
printf("%d",num[i]);
}
putchar('\n');
return;
}
num[cur]=0;
permutation(cur+1,ham,num);
num[cur]=1;
permutation(cur+1,ham+1,num);
//num[cur] returns to original,so as not to disturb further search
num[cur]=0;
}
int main()
{
//
freopen("input.txt","r",stdin);
int numcase;
int num[20];
scanf("%d",&numcase);
while(numcase--)
{
scanf("%d%d",&len,&hmax);
memset(num,0,sizeof(num));
permutation(0,0,num);
if(numcase) putchar('\n');
}
}