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;
    }
  • 相关阅读:
    Zookeeper_ZAB协议
    Zookeeper_Paxos算法
    Eureka的表兄弟Zookeeper理论基础
    SSE:服务器推送事件
    BIO、NIO、AIO入门认识
    c语言float、double数据保留2位小数
    c语言在8位bmp位图上画一个框并另存
    C语言在24真彩位图上指定位置处画一条横线
    vs2010 opengl 环境搭建
    osg模型操作之替代节点
  • 原文地址:https://www.cnblogs.com/yohaha/p/5208841.html
Copyright © 2011-2022 走看看