题意:先给出序列的长度,然后给出1的个数,输出符合这个要求的序列的全排列。

题解:根据长度,前面全是零,然后最后按1的个数将1补齐,从这个序列开始,用next_permutation(),将所有下一个排列输出。

#include <stdio.h>
#include <algorithm>
using namespace std;
int main() {
	int t, a, b, s[20], i, j;
	scanf("%d", &t);
	while (t--) {
		scanf("%d%d", &a, &b);
		for (i = 0; i < a - b; i++)
			s[i] = 0;
		for (j = i; j < a; j++)
			s[j] = 1;
		do {
			for (i = 0; i < a; i++)
				printf("%d", s[i]);
			printf("\n");
		}while (next_permutation(s, s + a));
		if (t)
			printf("\n");
	}
	return 0;
}