deushiro

Untitled

Feb 13th, 2020
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int maxi = 0;
  6.  
  7. vector<bool> used;
  8.  
  9. void rec(int n, int m, vector<vector<int>> &a, int ans){
  10.     maxi = max(ans, maxi);
  11.     for(int i = 0; i < n; ++i){
  12.         cout << used[i] << " ";
  13.     }
  14.     cout << endl;
  15.     for(int i = 0; i < m; ++i){
  16.         cout << i << endl;
  17.         bool flag = true;
  18.         for(int j : a[i]){
  19.             if(used[j])
  20.                 flag = false;
  21.         }
  22.         if(flag){
  23.             for(int j : a[i])
  24.                 used[j] = true;
  25.             rec(n, m, a, ans + a[i].size());
  26.             for(int j : a[i])
  27.                 used[j] = false;
  28.             rec(n, m, a, ans);
  29.         }
  30.     }
  31. }
  32.  
  33. int main() {
  34.     int tt;
  35.     cin >> tt;
  36.     while(tt--){
  37.         int n, m, k;
  38.         cin >> n >> m;
  39.         vector<vector<int>> a(m, vector<int>());
  40.         used.resize(n);
  41.         for(int i = 0; i < m; ++i){
  42.             cin >> k;
  43.             for(int j = 0; j < k; ++j){
  44.                 int x;
  45.                 cin >> x;
  46.                 x--;
  47.                 maxi = 0;
  48.                 a[i].push_back(x);
  49.             }
  50.         }
  51.         rec(n, m, a, 0);
  52.         cout << maxi << endl;
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment