fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n,k;
  4. bool check(string s){
  5. int cnt = 0;
  6. for(char c : s) {
  7. if(c == '1')cnt++;
  8. }
  9. return cnt == k;
  10. }
  11. int main(){
  12. int t;
  13. cin >> t;
  14. while(t--){
  15. cin >> n >> k;
  16. bool found = false;
  17. for(int i = 0; i < (1 << n);i++){
  18. string s;
  19. for(int j= 0; j < n;j++){
  20. if( i & (j << 1)) s+= "1";
  21. else s+= "0";
  22. }
  23. if(check(s)){
  24. found = true;
  25. cout << s << endl;
  26. }
  27. }
  28. if(!found) cout << endl;
  29.  
  30. }
  31. }
Success #stdin #stdout 0.01s 5272KB
stdin
2

4 2

3 2
stdout
0101
0101
0011
0011
0101
0101
0011
0011
011
011