Uva--729 (暴力排序)
2014-07-10 11:41:47
题意&思路:一个长为n的串里有h个1,n-h个0,输出全排列,next_permutation。不说啥了,注意输出。
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 using namespace std; 6 7 int main(){ 8 char s[20]; 9 int Case,n,h; 10 scanf("%d",&Case); 11 while(Case--){ 12 scanf("%d %d",&n,&h); 13 for(int i = 0; i < 20; ++i) s[i] = '0'; 14 s[n] = '\0'; 15 int len = n - 1; 16 while(h--) 17 s[len--] = '1'; 18 cout << s << endl; 19 while(next_permutation(s,s + n)) cout << s << endl; 20 if(Case) cout << endl; 21 } 22 return 0; 23 }