File tree 1 file changed +46
-0
lines changed
1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+
3
+ using namespace std ;
4
+ using ll = int64_t ;
5
+ using ff = long double ;
6
+
7
+ int N, M;
8
+ vector<int > A;
9
+ vector<int > C;
10
+
11
+ int solve () {
12
+ int const inf = 1e9 ;
13
+ int const S = 1 << N;
14
+ vector<int > DP (S, inf);
15
+ DP[0 ] = 0 ;
16
+ for (int s = 0 ; s < S; ++s) {
17
+ if (DP[s] == inf) continue ;
18
+ for (int i = 0 ; i < M; ++i) {
19
+ int ns = s | C[i];
20
+ DP[ns] = min (DP[ns], DP[s] + A[i]);
21
+ }
22
+ }
23
+ return (DP[S-1 ] == inf ? -1 : DP[S-1 ]);
24
+ }
25
+
26
+ int main () {
27
+ ios_base::sync_with_stdio (false );
28
+ cin.tie (0 ); cout.tie (0 );
29
+
30
+ cin >> N >> M;
31
+ A.assign (M, 0 );
32
+ C.assign (M, 0 );
33
+ for (int i = 0 ; i < M; ++i) {
34
+ int b;
35
+ cin >> A[i] >> b;
36
+ for (int j = 0 ; j < b; ++j) {
37
+ int c;
38
+ cin >> c;
39
+ --c;
40
+ C[i] |= (1 << c);
41
+ }
42
+ }
43
+ cout << solve () << endl;
44
+
45
+ return 0 ;
46
+ }
You can’t perform that action at this time.
0 commit comments