fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. void solve() {
  9. int N, H;
  10. cin >> N >> H;
  11.  
  12. // Tạo chuỗi ban đầu có N - H ký tự '0' và H ký tự '1'
  13. string s = "";
  14. for (int i = 0; i < N - H; i++) s += '0';
  15. for (int i = 0; i < H; i++) s += '1';
  16.  
  17. // In ra hoán vị đầu tiên và sinh các hoán vị tiếp theo theo thứ tự từ điển
  18. do {
  19. cout << s << "\n";
  20. } while (next_permutation(s.begin(), s.end()));
  21. }
  22.  
  23. int main() {
  24. // Tối ưu hóa I/O
  25. ios_base::sync_with_stdio(false);
  26. cin.tie(NULL);
  27.  
  28. int T;
  29. if (cin >> T) {
  30. while (T--) {
  31. solve();
  32. if (T > 0) {
  33. cout << "\n"; // Dòng trống phân tách giữa các bộ test
  34. }
  35. }
  36. }
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty