按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. Android蓝牙——HID开发

    代码地址如下:http://www.demodashi.com/demo/13891.html 原文地址: https://blog.csdn.net/VNanyesheshou/article/de ...

  2. Maven--要点笔记

    --maven笔记 1.maven命令 2.archetype插件:用于创建符合maven规定的文件夹骨架   命令: mvn archetype:generate 3. 坐标:构件 仓库: 本地仓库 ...

  3. cat /proc/iomem

    在proc目录下有iomem和ioports文件,其主要描述了系统的io内存和io端口资源分布. 对于外设的访问,最终都是通过读写设备上的寄存器实现的,寄存器不外乎:控制寄存器.状态寄存器和数据寄存器 ...

  4. EMQ学习---客户链接资源消耗

    Erlang进程消耗EMQ对客户端链接使用链接进程(emqtt_client)和session进程(emqtt_session)分开的策略. 当一个mqtt的客户端连接到EMQ的服务器上的时候,首先会 ...

  5. docker 容器自启动

    我们设置了docker自启动后,docker可以管理各种容器了,对于容器我们也可以设置重启的策略. 在容器退出或断电开机后,docker可以通过在容器创建时的--restart参数来指定重启策略: # ...

  6. find_if查找vector内对象的成员 作为菜鸟一直不会用也不敢用

    用stl的find方法查找一个包含简单类型的vector中的元素是很简单的,例如 vector<string> strVec; find(strVec.begin(),strVec.end ...

  7. pow(x,y)函数的实现算法(递归函数)

    函数pow(x,y)实现运算x^y,即x的y次方,这里x和y都为整数. 算法的基本思想是,减少乘法次数,重复利用结算结果,例如: x^4,如果逐个相乘的话,需要四次乘法.如果我们这样分解(x^2)*( ...

  8. vim资源帖

    vimscript教程 http://learnvimscriptthehardway.stevelosh.com/ 阿信的vimscript http://www.axiaoxin.com/arti ...

  9. 李洪强iOS经典面试题34-求两个链表表示的数的和

    李洪强iOS经典面试题34-求两个链表表示的数的和 问题 给你两个链表,分别表示两个非负的整数.每个链表的节点表示一个整数位. 为了方便计算,整数的低位在链表头,例如:123 在链表中的表示方式是: ...

  10. vue 和ng的区别

    vue:    读音:    v-u-e    view vue到底是什么?        一个mvvm框架(库).和angular类似        比较容易上手.小巧    mvc:       ...