UVA 729 - The Hamming Distance Problem

来源:互联网 发布:网络的重要性的名言 编辑:程序博客网 时间:2024/06/06 00:25

题目大意:给你一个给定长度 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;}


0 0
原创粉丝点击