UVA 729 - The Hamming Distance Problem

题目大意:给你一个给定长度 N 的字符串,其中有 H 个 1 ,  求其全排列

#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
	int t;
	scanf("%d", &t);
	while (t--) {
		int num, one;
		char s[20] = {0};
		scanf("%d%d", &num, &one);

		for (int i = 0; i < num ; i++)
			s[i] = (i >= num - one ? '1' : '0');

		do {
			puts(s);
		} while (next_permutation(s, s + num));

		if (t)
			printf("\n");
	}

	return 0;
}


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