Created
September 12, 2023 00:19
-
-
Save estelabn/2a6677f555eb86fa3fb6d996e22329a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
int main(){ | |
ios_base::sync_with_stdio(false); | |
int n,k; cin >> n >> k; | |
vector<int> v(n); | |
for(int i=0; i<n; i++){ | |
int h; cin >> h; | |
int j = 0; | |
for(int l =0; l<h; l++){ | |
int x; cin >> x; x--;j+= (1<<x); | |
} | |
v[i] = j; | |
} | |
vector<vector<int>> dp(1<<k, vector<int> (1<<k, 500)); | |
dp[0][0] = 0; | |
for(auto i: v) for(int j = 0; j<(1<<k); j++) for(int l = 0; l< (1<<k); l++){ | |
int inv = i ^ ((1<<k) - 1); | |
dp[j][l] = min(dp[j][l], dp[(j|i) - i][(l|inv) - inv] + 1); | |
} | |
if(dp[(1<<k)-1][(1<<k) -1] == 500) cout << -1 << endl; | |
else cout << dp[(1<<k)-1][(1<<k) -1] << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment