uva729 The Hamming Distance Problem

来源:互联网 发布:java swing 开源项目 编辑:程序博客网 时间:2024/06/06 03:17

uva729 The Hamming Distance Problem 

全排列水题

存1的时候要注意位置。。。 刚开始因为这个不小心wa了
#include <algorithm>using namespace std;#include <stdio.h>#include <string.h>int t;int n, h;int i;char sb[25];int main(){scanf("%d", &t);while (t --){memset(sb, '0', sizeof(sb));scanf("%d%d", &n, &h);for(i = n - 1; i > n - 1 - h; i --){sb[i] = '1';}sb[n] = '\0';printf("%s\n", sb);while (next_permutation(sb, sb + n)){printf("%s\n", sb);}if(t)printf("\n");}return 0;}