UVa 729 The Hamming Distance Problem【枚举排列】

题意:给出数组的长度n,给出h,表示这个数组里面含有h个1,求其所有的排列

用next_permutation就可以了

 1 #include<iostream>  

 2 #include<cstdio>  

 3 #include<cstring> 

 4 #include <cmath> 

 5 #include<stack>

 6 #include<vector>

 7 #include<map> 

 8 #include<set>

 9 #include<queue> 

10 #include<algorithm>  

11 using namespace std;

12 

13 #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)

14 

15 typedef long long LL;

16 const int INF = (1<<30)-1;

17 const int mod=1000000007;

18 const int maxn=100005;

19 

20 int p[maxn];

21 

22 int main(){

23     int T;

24     scanf("%d",&T);

25     while(T--){

26         

27         int n,h;

28         scanf("%d %d",&n,&h);

29         

30         for(int i=0;i<n;i++){

31             if(i<h) p[i]=1;

32             else p[i]=0;

33         }

34         

35         sort(p,p+n);

36         

37         do{

38             for(int i=0;i<n;i++) printf("%d",p[i]);

39             printf("\n");

40         }while(next_permutation(p,p+n));

41         

42         if(T)  printf("\n");

43     }

44     return 0;

45 }
View Code

 

你可能感兴趣的:(uva)