AtcoderABC-142E-GetEverything

AtcoderABC-142E-GetEverything

 

 AtcoderABC-142E-GetEverything

 典型的数位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]);
}

 

上一篇:进程间通信效率测试


下一篇:idtcp实现文件下载和上传