http://oj.chilanggialai.edu.vn/problem/cloj01love
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define int long long
#define pii pair<long long, long long>
#define endl "\n"
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define FILE(A) freopen(A".INP", "r", stdin); freopen(A".OUT", "w", stdout)
using namespace std;
const int N = 101+5;
const int oo = 1e16 ;
const int MOD = 1e9+7;
const int BASE = 31 ;
int n,m, a[N], c[N];
int dp[1<<15], pre[1<<15];
void RESET() {
for (int mask=0;mask < (1<<n);mask++) {
pre[mask] = dp[mask];
dp[mask] = oo;
}
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
for (int i=1;i <= m;i++) {
int k,x;
cin >> k; a[i] = 0;
while(k--) {
cin >> x; a[i] = a[i] | (1<<(x-1));
}
cin >> c[i];
}
for (int mask=0;mask < (1<<n);mask++) {
dp[mask] = oo;
}
dp[0] = 0;
for (int i=1;i <= m;i++) {
RESET();
for (int mask=0;mask < (1<<n);mask++) {
dp[mask | a[i]] = min(dp[mask | a[i]], pre[mask] + c[i]);
dp[mask] = min(dp[mask], pre[mask]);
}
}
cout << dp[(1<<n)-1];
cerr << "Time elapsed: " << TIME << "s.\n";
return 0;
}
// Nguyen Minh Hieu - 2008 - Gia Lai.
// https://hieuhfgr.pythonanywhere.com/