Advertisement
yeskendir_sultanov

Bitmask

May 18th, 2024
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define pb push_back
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int n, k;
  9.     cin >> n >> k;
  10.     int w[n];
  11.     for (int i = 0; i < n; ++i) {
  12.         cin >> w[i];
  13.     }
  14.  
  15.     if (n > 20) {
  16.         cout << "1";
  17.         return 0;
  18.     }
  19.    
  20.     int ans = 0;
  21.    
  22.     for (int mask = 0; mask < (1 << n); ++mask) {
  23.         int cur = 0;
  24.         set<int> b;
  25.        
  26.         for (int i = n - 1; i >= 0; --i) {
  27.             if ((mask & (1 << i)) != 0) {
  28.                 cur++;
  29.                 b.insert(w[i]);
  30.             }
  31.         }
  32.        
  33.         if (cur == k && b.size() == k) {
  34.             ans++;    
  35.         }
  36.     }
  37.    
  38.     cout << ans;
  39.    
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement