SHARE
TWEET

Untitled

a guest Dec 16th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // Created by buraindo on 16.12.18.
  3. //
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. typedef long long ll;
  11.  
  12. int main()
  13. {
  14.     freopen("cycles.in", "r", stdin);
  15.     freopen("cycles.out", "w", stdout);
  16.     int n, m;
  17.     cin >> n >> m;
  18.     ll allXCount = 1 << n;
  19.     vector<bool> used(static_cast<unsigned long>(allXCount), false);
  20.     vector<int> powers(static_cast<unsigned long>(allXCount), 0);
  21.     vector<int> weights(static_cast<unsigned long>(n));
  22.     for (int i = 0; i < n; i++) {
  23.         cin >> weights[i];
  24.     }
  25.     for (int i = 0; i < m; i++) {
  26.         int mask = 0;
  27.         int size;
  28.         cin >> size;
  29.         for (int j = 0; j < size; j++) {
  30.             int id;
  31.             cin >> id;
  32.             id--;
  33.             mask |= (1 << id);
  34.         }
  35.         used[mask] = true;
  36.         powers[mask] = size;
  37.     }
  38.     ll result = 0L;
  39.     for (int i = 0; i < allXCount; i++) {
  40.         if (used[i]) {
  41.             for (int j = 0; j < n; j++) {
  42.                 int x = 1 << j;
  43.                 used[x | i] = true;
  44.             }
  45.         }
  46.         else {
  47.             ll temp = 0L;
  48.             for (int j = 0; j < n; j++){
  49.                 int x = 1 << j;
  50.                 if (x & i != 0) {
  51.                     temp += weights[j];
  52.                 }
  53.             }
  54.             result = max(result, temp);
  55.         }
  56.     }
  57.     cout << result << endl;
  58.     return 0;
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top