典型的数位DP
#include<bits/stdc++.h> using namespace std; int n, m, a, b, c, dp[4096]; int main() { cin >> n >> m; int s = (1 << n); dp[0] = 0; for(int i = 1; i < s; i++) dp[i] = 1e9; while(m--) { cin >> a >> b; int t = 0; while(b--) { cin >> c; t |= (1 << --c); } for(int i = 0; i < s; i++) { if(dp[i] != 1e9) dp[i | t] = min(dp[i | t], dp[i] + a); } } cout << (dp[s-1] == 1e9 ? -1 : dp[s-1]); }