UVA 729 The Hamming Distance Problem
题目大意:给出数字个数和1的个数,输出全部排列
解题思路:next_permutation调用
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
char str[100];
int main() {
int n;
cin >> n;
while(n--) {
memset(str, '\0', sizeof(str));
int m, x;
cin >> m >> x;
for(int i = 0; i < m - x; i++)
str[i] = '0';
for(int i = m - x; i < m; i++)
str[i] = '1';
puts(str);
while(next_permutation(str, str + strlen(str)))
puts(str);
if(n)
printf("\n");
}
return 0;
}