题目链接

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-;
const int mod = 1e18+;
const ll inf = 5e18+;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
struct node
{
int x, k, c;
bool operator < (node a) const
{
return k<a.k;
}
}a[];
ll dp[(<<)];
int main()
{
int n, m, b, t, x;
cin>>n>>m>>b;
int ed = (<<m)-;
for(int i = ; i<=n; i++) {
cin>>a[i].x>>a[i].k>>t;
while(t--) {
scanf("%d", &x);
a[i].c |= <<(x-);
}
}
sort(a+, a++n);
for(int i = ; i<=ed; i++) {
dp[i] = inf;
}
ll ans = inf;
for(int i = ; i<=n; i++) {
for(int j = ; 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 ;
}

codeforces 417D. Cunning Gena 状压dp的更多相关文章

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

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

  2. codeforces Diagrams & Tableaux1 (状压DP)

    http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132 ...

  3. Codeforces 917C - Pollywog(状压 dp+矩阵优化)

    UPD 2021.4.9:修了个 typo,为啥写题解老出现 typo 啊( Codeforces 题目传送门 & 洛谷题目传送门 这是一道 *2900 的 D1C,不过还是被我想出来了 u1 ...

  4. Codeforces 79D - Password(状压 dp+差分转化)

    Codeforces 题目传送门 & 洛谷题目传送门 一个远古场的 *2800,在现在看来大概 *2600 左右罢( 不过我写这篇题解的原因大概是因为这题教会了我一个套路罢( 首先注意到每次翻 ...

  5. Codeforces 544E Remembering Strings 状压dp

    题目链接 题意: 给定n个长度均为m的字符串 以下n行给出字符串 以下n*m的矩阵表示把相应的字母改动成其它字母的花费. 问: 对于一个字符串,若它是easy to remembering 当 它存在 ...

  6. codeforces 21D. Traveling Graph 状压dp

    题目链接 题目大意: 给一个无向图, n个点m条边, 每条边有权值, 问你从1出发, 每条边至少走一次, 最终回到点1. 所走的距离最短是多少. 如果这个图是一个欧拉回路, 即所有点的度数为偶数. 那 ...

  7. Codeforces 895C - Square Subsets 状压DP

    题意: 给了n个数,要求有几个子集使子集中元素的和为一个数的平方. 题解: 因为每个数都可以分解为质数的乘积,所有的数都小于70,所以在小于70的数中一共只有19个质数.可以使用状压DP,每一位上0表 ...

  8. CodeForces 327E Axis Walking(状压DP+卡常技巧)

    Iahub wants to meet his girlfriend Iahubina. They both live in Ox axis (the horizontal axis). Iahub ...

  9. Codeforces ----- Kefa and Dishes [状压dp]

    题目传送门:580D 题目大意:给你n道菜以及每道菜一个权值,k个条件,即第y道菜在第x道后马上吃有z的附加值,求从中取m道菜的最大权值 看到这道题,我们会想到去枚举,但是很显然这是会超时的,再一看数 ...

随机推荐

  1. 在.NET中快速创建一个5GB、10GB或更大的空文件

    对于通过UDP进行打文件传输的朋友应该首先会考虑到一个问题,那就是由于UDP并不会根据先来先到原则进行发送,也许你发送端发送的时候是以包1和包2的顺序传输的,但接收端可能以包2和包1 的顺序来进行接收 ...

  2. 4.跟我学solr---SolrRequestHandler具体解释

    概述 我们在使用solr admin在做查询的时候,能够看到Request-Hander(qt)输入栏中有"/select"这样一个uri.当我们点击查询的时候所发起的请求是这种. ...

  3. 达内TTS6.0课件oop_day01

  4. mysql主从切换步骤

    1>   正常切换 1)从server检查SHOW PROCESSLIST语句的输出,直到你看到Has read all relaylogwaiting for the slave I/O th ...

  5. opacity在IE6~8下无效果,解决的办法

    opacity在IE6~8下无效果,解决的办法 问题出现时rgba()在ie6下不出效果,最后查到是opacity的问题. opacity是css3时出现的,目前主流浏览器都支持.but老IE是个麻烦 ...

  6. JS把字符串转换为数字的方法

     方法: (1)Number(),强制类型转换,接受一个参数. (2)parseInt(),把字符串转换为整形数字,可以接受一个或两个参数,其中第二个参数代表转换的基数,能够正确的将二进制.八进制.十 ...

  7. ##DAY14——StoryBoard

    •iOS下可视化编程分为两种⽅式:xib和storyboard. •在使用xib和storyboard创建GUI过程中,以XML文件格式 存储在Xcode中,编译时生成nib的二进制文件.在运行时, ...

  8. <jsp:directive.page>标签

    directive 英 [dɪ'rektɪv; daɪ-] 美 [daɪ'rɛktɪv] n. 指示:指令 adj. 指导的:管理的 等效于 <%page import="com.ct ...

  9. 根据用户的ID查用户的名字

    awk -F: '{if($3==0){print $1}}'  /etc/passwd

  10. HDU2955-Robberies

    描述: The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usual ...