Josif_tepe

Untitled

Nov 3rd, 2025
706
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <queue>
  5. #include <cstring>
  6. #include <map>
  7. using namespace std;
  8. typedef long long ll;
  9.  
  10. const int maxn = 1e5 + 10;
  11. const ll INF = 1e16;
  12.  
  13.  
  14. int power(int a, int b) {
  15.     int res = 1;
  16.     for(int i = 0; i < b; i++) {
  17.         res *= a;
  18.     }
  19.     return res;
  20. }
  21. int n, k;
  22. string to_binary(int x) {
  23.     string res = "";
  24.    
  25.     while(x > 0) {
  26.         int rem = x % 2;
  27.         res += rem + '0';
  28.        
  29.         x /= 2;
  30.     }
  31.     while((int) res.size() < k) {
  32.         res += "0";
  33.     }
  34.     reverse(res.begin(), res.end());
  35.     return res;
  36. }
  37. int main()
  38. {
  39.     cin >> n;
  40.    
  41.     cin >> k;
  42.    
  43.     vector<string> v(k);
  44.     for(int i =0 ; i < k; i++) {
  45.         cin >> v[i];
  46.     }
  47.    
  48.     int power_of_2 = power(2, k);
  49.    
  50.     for(int i = 0; i < power_of_2; i++) {
  51.         string tmp = to_binary(i);
  52.         vector<string> v_tmp;
  53.         for(int j = 0; j < (int) tmp.size(); j++) {
  54.             if(tmp[j] == '1') {
  55.                 v_tmp.push_back(v[j]);
  56.             }
  57.         }
  58.         if((int) v_tmp.size() == n) {
  59.             for(string s: v_tmp) {
  60.                 cout << s << " " ;
  61.             }
  62.             cout << endl;
  63.         }
  64.     }
  65.  
  66.  
  67.     return 0;
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment