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 n, m 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 xi, ki 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

看到m那么小,就直接想到状压dp了,但是这里有一个monitors的限制,不能暴力枚举这个值
可以先把输入数据按每一个人的monitors排序,这样从小到大枚举每一个人,边递推边记录了答案就行

/*************************************************************************> File Name: CF417D.cpp> Author: ALex> Mail: zchao1995@gmail.com > Created Time: 2015年03月16日 星期一 12时33分11秒************************************************************************/#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;const double pi = acos(-1.0);
const long long inf = (1LL << 60);
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;LL dp[(1 << 20) + 10];struct node
{int sta;int cost;int num;
}fri[110];int cmp (node a, node b)
{return a.num < b.num;
}int main ()
{int n, m, b;while (~scanf("%d%d%d", &n, &m, &b)){for (int i = 0; i <= (1 << m); ++i){dp[i] = inf;}dp[0] = 0;for (int i = 1; i <= n; ++i){int cnt;fri[i].sta = 0;int x;scanf("%d%d%d", &fri[i].cost, &fri[i].num, &cnt);for (int j = 0; j < cnt; ++j){scanf("%d", &x);fri[i].sta |= (1 << (x - 1));}}LL ans= inf;sort (fri + 1, fri + 1 + n, cmp);for (int i = 1; i <= n; ++i){for (int j = 0; j < (1 << m); ++j){dp[j | fri[i].sta] = min (dp[j] + fri[i].cost, dp[j | fri[i].sta]);}ans = min (ans, dp[(1 << m) - 1] + (LL)fri[i].num * b);}if (ans >= inf){printf("-1\n");}else{cout << ans << endl;}}return 0;
}

CF417D--- Cunning Gena(排序+状压dp)相关推荐

  1. HDU 4917 Permutation(拓扑排序 + 状压DP + 组合数)

    题目链接 Permutation 题目大意:给出n,和m个关系,每个关系为ai必须排在bi的前面,求符合要求的n的全排列的个数. 数据规模为n <= 40,m <= 20. 直接状压DP空 ...

  2. 【状压DP】滚榜(P7519)

    正题 P7519 题目大意 n个队伍,排名先按分数排序再按编号排序,每个队伍有一个初始分数 aia_iai​,和一个附加分数 bib_ibi​ 对于一个合法的 bib_ibi​ 序列,按 bib_ib ...

  3. [NOI2015] 寿司晚宴(状压DP)

    洛谷题目传送门 解题思路 首先考虑30pts的做法 因为两人选的数必须互质,因此可以想到只要维护二者没有共同质因子就行了 因为质因子个数很少,考虑状压DP 设 dp[S][T] 表示 A选了数的质因子 ...

  4. POJ 1038 Bugs Integrated Inc (复杂的状压DP)

    \(POJ~1038~~*Bugs~Integrated~Inc:\) (复杂的状压DP) \(solution:\) 很纠结的一道题目,写了大半天,就想练练手,结果这手生的.其实根据之前那道炮兵阵地 ...

  5. codeforces 8C. Looking for Order 状压dp

    题目链接 给n个物品的坐标, 和一个包裹的位置, 包裹不能移动. 每次最多可以拿两个物品, 然后将它们放到包里, 求将所有物品放到包里所需走的最小路程. 直接状压dp就好了. #include < ...

  6. UVA10296 Jogging Trails(中国邮递员问题)(欧拉回路、一般图最大权匹配 / 状压DP)

    整理的算法模板合集: ACM模板 目录 思路 UVA10296 Jogging Trails 题目翻译: 给你n个点,m条无向边,每条边有一定的距离数值,构造成一个连通图.问从任意一点出发,遍历所有的 ...

  7. POJ 2411 Mondriaan‘s Dream(最清楚好懂的状压DP讲解)(连通性状态压缩DP)

    poj 2411 Mondriaan's Dream(最清晰的状压DP解析) 闫氏DP大法好 我们这里是一列一列地来,因为是一个棋盘性的状态压缩DP,从哪个方向都一样 摆放的小方格总方案数 等价于 横 ...

  8. 【每日DP】day2、P1879 [USACO06NOV]Corn Fields G玉米地(状压DP模板题)难度⭐⭐⭐★

    昨天的每日DP我还在写01背包,今天就到状压DP了,真刺激. P1879 [USACO06NOV]Corn Fields G 题目链接 输入 2 3 1 1 1 0 1 0 输出 9 一道简单的状压D ...

  9. hdu 4778 Gems Fight! 状压dp

    转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...

  10. 【洛谷 P1896】[SCOI2005]互不侵犯(状压dp)

    题目链接 题意:在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. 这是道状压\(DP\)好题啊.. ...

最新文章

  1. Java解压zip文件(文本)压缩包
  2. python 类-Python入门--一篇搞懂什么是类
  3. 2021考研时间公布 2020年12月26日至27日进行初试
  4. opengl载入多个3ds模型失败记
  5. C#实现所有经典排序算法汇总
  6. win10桌面倒计时插件_win10 桌面如何做到清爽好看?这篇教程给你答案
  7. 图合成与差分隐私(图结构和节点属性)论文笔记
  8. copy 自定义对象
  9. 包/logging模块/hashlib模块/openpyxl模块/深浅拷贝
  10. c语言连接mysql_0基础掌握Django框架(14)MySQL相关软件
  11. 离散数学 习题篇 —— 谓词公式练习
  12. 玩转大麦盒子airplay
  13. 计算机无法启动打印服务,Win7无法启动print spooler服务报错1068怎么办?
  14. PROFINET 建立连接的原理
  15. Spring之DI依赖注入
  16. “凸现”三围的健身运动法(图)
  17. 小程序z-index层级问题view组件坑,z-index失效
  18. 无代码开发的未来是什么样的?
  19. 1253 Dungeon Master
  20. office2016 使用KMS破解无法连接服务器

热门文章

  1. H. Zebras and Ocelots -ICPC North Central NA Contest 2017
  2. 邮件服务器没有MX类型,mx记录和邮件服务器的关系究竟是什么?
  3. 9.5.4英语词典。设计字典记录小张新学的英文单词和中文翻译,并能根据英文来查找中文翻译,当用户输入1,按提示添加新的单词和中文;用户输入2可查找英文单词的对应中文翻译,输入3,退出程序。
  4. Springboot 前后端交互 Long类型传输 前端获取数据受限
  5. UE-战斗无止境的UI实现
  6. office的笔记本:OneNote使用技巧
  7. 【HDU 6638】Snowy Smile(线段树求区间连续最大和)
  8. 01炼数成金TensorFlow基本概念
  9. 此Flash Player 与您的地区不相容,请重新安装Adobe Flash Player问题解决
  10. 《菜鸟教程》 EUI卡牌游戏制作