按monitor排序,然后状压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 thei-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

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm> using namespace std; long long int n,m,b;
long long int dp[ (1<<20)+10 ]; struct FD
{
long long int x,k,pb;
}fd[120]; bool cmp(FD a,FD b)
{
return a.k<b.k;
} int main()
{
scanf("%d%d%d",&n,&m,&b);
for(int i=0;i<n;i++)
{
long long int xi,ki,mi,problem=0;
cin>>xi>>ki>>mi;
for(int j=0;j<mi;j++)
{
int a;
scanf("%d",&a);
a--;
problem|=(1<<a);
}
fd[i]=(FD){xi,ki,problem};
}
sort(fd,fd+n,cmp);
int state=(1<<m)-1;
for(int i=0;i<=state;i++) dp[i]=(long long int )(1LL<<60);
dp[0]=0;
long long int ans=(long long int )(1LL<<60);
for(int i=0;i<n;i++)
{
for(int j=0;j<=state;j++)
{
dp[j|fd[i].pb]=min(dp[j|fd[i].pb],dp[j]+fd[i].x);
}
ans=min(ans,dp[state]+fd[i].k*b);
}
if(ans==(long long int )(1LL<<60)) ans=-1;
cout<<ans<<endl;
return 0;
}

Codeforces 417 D. Cunning Gena的更多相关文章

  1. 【codeforces 417D】Cunning Gena

    [题目链接]:http://codeforces.com/problemset/problem/417/D [题意] 有n个人共同完成m个任务; 每个人有可以完成的任务集(不一定所有任务都能完成); ...

  2. Codeforces 417D Cunning Gena(状态压缩dp)

    题目链接:Codeforces 417D Cunning Gena 题目大意:n个小伙伴.m道题目,每一个监视器b花费,给出n个小伙伴的佣金,所须要的监视器数,以及能够完毕的题目序号. 注意,这里仅仅 ...

  3. Cunning Gena CodeForces - 417D

    Cunning Gena CodeForces - 417D 题意 先将小伙伴按需要的监视器数量排序.然后ans[i][j]表示前i个小伙伴完成j集合内题目所需最少钱.那么按顺序枚举小伙伴,用ans[ ...

  4. codeforces 417D. Cunning Gena 状压dp

    题目链接 D. Cunning Gena time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. FZU 2165 v11(最小重复覆盖)+ codeforces 417D Cunning Gena

    告诉你若干个(<=100)武器的花费以及武器能消灭的怪物编号,问消灭所有怪物(<=100)的最小花费...当然每个武器可以无限次使用,不然这题就太水了╮(╯▽╰)╭ 这题当时比赛的时候连题 ...

  6. Codeforces 417 C

    Football Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Sta ...

  7. RCC 2014 Warmup (Div. 2) 蛋疼解题总结

    A. Elimination time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. Codeforces Round #339 (Div. 2) B. Gena's Code 水题

    B. Gena's Code 题目连接: http://www.codeforces.com/contest/614/problem/B Description It's the year 4527 ...

  9. Codeforces Round #339 Div.2 B - Gena's Code

    It's the year 4527 and the tanks game that we all know and love still exists. There also exists Grea ...

随机推荐

  1. google全球ip地址库

    当我们为不能使用google搜索业务时,这里有全球的google ip库,能够使用当中任一个来利用google搜索 https://github.com/justjavac/Google-IPs ht ...

  2. 【Redis】redis 五种数据结构详解(string,list,set,zset,hash)

    redis 五种数据结构详解(string,list,set,zset,hash) Redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存 ...

  3. eval函数处理JSON数据需要加括号

    在将服务器端构建好的JSON数据转化为可用的JavaScript对象时常常使用eval函数.如下: var dataJson = eval('(' + data + ')'); 在转化的时候需要将JS ...

  4. Android Design与Holo Theme详解

    在 国内,有个很有意思的现状.一方面,几个国内最大的公司/企业的客户端/应用依旧冥顽不灵,丝毫不愿意遵循 Android Design,以各种扯淡的理由坚持使用 iOS UI 或者 Metro UI, ...

  5. HDU 4946 Area of Mushroom 共线凸包

    题意是在二维平面上 给定n个人 每一个人的坐标和移动速度v 若对于某个点,仅仅有 x 能最先到达(即没有人能比x先到这个点或者同一时候到这个点) 则这个点称作被x占有 若有人能占有无穷大的面积 则输出 ...

  6. <class 'Salesman.admin.UsrUserAdmin'>: (admin.E012) There are duplicate field(s) in 'fieldsets[0][1]'.

    ieldsets = ( ['Main', { 'fields': ('user_name', 'real_name', 'concat_name','phone_no','charge_person ...

  7. Ubuntu中建立ftp 503错误解决办法

    The problem is because your folder is owned by root, instead of ftpuser. To fix it run: sudo chown - ...

  8. 邁向 RHCE 之路 (Day26) - Apache 網頁伺服器

    本篇將在 SELinux 安全機制及 IPTables 防火牆開啟的環境下實作,分別實作簡單網頁服務及虛擬主機 Virtual Host 設定,最後則是實作網頁中需要保護網頁時可以透過 .htacce ...

  9. ubuntu下安装自动补全YouCompleteMe

    一.安装预备软件.#vim要带python2.7的支持,curl是下载插件必须用到的软件,还有git apt install vim-nox-py2 curl git #安装python头文件 apt ...

  10. Intel 5 6 7 8系列芯片组介绍

    Intel 5 6 7 8系列芯片组介绍 Iknow.2015-11-05 22:40|知识编号:122257 操作步骤: [Inetl 5.6.7.8系列芯片组介绍] 芯片组是主板电路的核心.一定意 ...