zoukankan      html  css  js  c++  java
  • codeforces 417D. Cunning Gena 状压dp

    题目链接

    D. Cunning Gena
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    A boy named Gena really wants to get to the "Russian Code Cup" finals, or at least get a t-shirt. But the offered problems are too complex, so he made an arrangement with his n friends that they will solve the problems for him.

    The participants are offered m problems on the contest. For each friend, Gena knows what problems he can solve. But Gena's friends won't agree to help Gena for nothing: the i-th friend asks Gena xi rubles for his help in solving all the problems he can. Also, the friend agreed to write a code for Gena only if Gena's computer is connected to at least ki monitors, each monitor costs b rubles.

    Gena is careful with money, so he wants to spend as little money as possible to solve all the problems. Help Gena, tell him how to spend the smallest possible amount of money. Initially, there's no monitors connected to Gena's computer.

    Input

    The first line contains three integers nm and b (1 ≤ n ≤ 100; 1 ≤ m ≤ 20; 1 ≤ b ≤ 109) — the number of Gena's friends, the number of problems and the cost of a single monitor.

    The following 2n lines describe the friends. Lines number 2i and (2i + 1) contain the information about the i-th friend. The 2i-th line contains three integers xiki and mi (1 ≤ xi ≤ 109; 1 ≤ ki ≤ 109; 1 ≤ mi ≤ m) — the desired amount of money, monitors and the number of problems the friend can solve. The (2i + 1)-th line contains mi distinct positive integers — the numbers of problems that the i-th friend can solve. The problems are numbered from 1 to m.

    Output

    Print the minimum amount of money Gena needs to spend to solve all the problems. Or print -1, if this cannot be achieved.

    Sample test(s)
    input
    2 2 1
    100 1 1
    2
    100 2 1
    1
    output
    202
    input
    3 2 5
    100 1 1
    1
    100 1 1
    2
    200 1 2
    1 2
    output
    205
    input
    1 2 1
    1 1 1
    1
    output
    -1


    直接状态压缩就可以, 具体看代码。 inf要超级大才可以过。
    #include <iostream>
    #include <vector>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <map>
    #include <set>
    #include <string>
    #include <queue>
    #include <stack>
    #include <bitset>
    using namespace std;
    #define pb(x) push_back(x)
    #define ll long long
    #define mk(x, y) make_pair(x, y)
    #define lson l, m, rt<<1
    #define mem(a) memset(a, 0, sizeof(a))
    #define rson m+1, r, rt<<1|1
    #define mem1(a) memset(a, -1, sizeof(a))
    #define mem2(a) memset(a, 0x3f, sizeof(a))
    #define rep(i, n, a) for(int i = a; i<n; i++)
    #define fi first
    #define se second
    typedef pair<int, int> pll;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int mod = 1e18+7;
    const ll inf = 5e18+7;
    const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
    struct node
    {
        int x, k, c;
        bool operator < (node a) const
        {
            return k<a.k;
        }
    }a[105];
    ll dp[(1<<23)];
    int main()
    {
        int n, m, b, t, x;
        cin>>n>>m>>b;
        int ed = (1<<m)-1;
        for(int i = 1; i<=n; i++) {
            cin>>a[i].x>>a[i].k>>t;
            while(t--) {
                scanf("%d", &x);
                a[i].c |= 1<<(x-1);
            }
        }
        sort(a+1, a+1+n);
        for(int i = 1; i<=ed; i++) {
            dp[i] = inf;
        }
        ll ans = inf;
        for(int i = 1; i<=n; i++) {
            for(int j = 0; j<=ed; j++) {
                dp[j|a[i].c] = min(dp[j|a[i].c], dp[j]+a[i].x);
            }
            ans = min(ans, 1LL*a[i].k*b+dp[ed]);
        }
        if(ans == inf) {
            puts("-1");
        } else {
            cout<<ans<<endl;
        }
        return 0;
    }
  • 相关阅读:
    acdream 1017: Fast Transportation 网络流层次图
    centos5的kernel source
    Linux内核源代码的阅读及相关工具介绍(转)
    gcc生成静态库和动态库(转)
    写一篇大家一看就会的教程《JNI初步》(转)
    jni.h
    5分钟学用Lucene
    (VC2005) picture 控件显示16*16的Icon
    (VC/MFC)通过结构体传递参数给线程
    (VC2005)MFC中添加控件的成员变量.
  • 原文地址:https://www.cnblogs.com/yohaha/p/5208841.html
Copyright © 2011-2022 走看看