Skip to content

Commit 2f74091

Browse files
committed
atcoder/abc142E
1 parent 0bf29d7 commit 2f74091

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

atcoder/abc142/E/main.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

0 commit comments

Comments
 (0)