codeforces 417D. Cunning Gena 状压dp
1 second
256 megabytes
standard input
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.
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.
Print the minimum amount of money Gena needs to spend to solve all the problems. Or print -1, if this cannot be achieved.
2 2 1
100 1 1
2
100 2 1
1
202
3 2 5
100 1 1
1
100 1 1
2
200 1 2
1 2
205
1 2 1
1 1 1
1
-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的更多相关文章
- Codeforces 417D Cunning Gena(状态压缩dp)
题目链接:Codeforces 417D Cunning Gena 题目大意:n个小伙伴.m道题目,每一个监视器b花费,给出n个小伙伴的佣金,所须要的监视器数,以及能够完毕的题目序号. 注意,这里仅仅 ...
- codeforces Diagrams & Tableaux1 (状压DP)
http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132 ...
- Codeforces 917C - Pollywog(状压 dp+矩阵优化)
UPD 2021.4.9:修了个 typo,为啥写题解老出现 typo 啊( Codeforces 题目传送门 & 洛谷题目传送门 这是一道 *2900 的 D1C,不过还是被我想出来了 u1 ...
- Codeforces 79D - Password(状压 dp+差分转化)
Codeforces 题目传送门 & 洛谷题目传送门 一个远古场的 *2800,在现在看来大概 *2600 左右罢( 不过我写这篇题解的原因大概是因为这题教会了我一个套路罢( 首先注意到每次翻 ...
- Codeforces 544E Remembering Strings 状压dp
题目链接 题意: 给定n个长度均为m的字符串 以下n行给出字符串 以下n*m的矩阵表示把相应的字母改动成其它字母的花费. 问: 对于一个字符串,若它是easy to remembering 当 它存在 ...
- codeforces 21D. Traveling Graph 状压dp
题目链接 题目大意: 给一个无向图, n个点m条边, 每条边有权值, 问你从1出发, 每条边至少走一次, 最终回到点1. 所走的距离最短是多少. 如果这个图是一个欧拉回路, 即所有点的度数为偶数. 那 ...
- Codeforces 895C - Square Subsets 状压DP
题意: 给了n个数,要求有几个子集使子集中元素的和为一个数的平方. 题解: 因为每个数都可以分解为质数的乘积,所有的数都小于70,所以在小于70的数中一共只有19个质数.可以使用状压DP,每一位上0表 ...
- CodeForces 327E Axis Walking(状压DP+卡常技巧)
Iahub wants to meet his girlfriend Iahubina. They both live in Ox axis (the horizontal axis). Iahub ...
- Codeforces ----- Kefa and Dishes [状压dp]
题目传送门:580D 题目大意:给你n道菜以及每道菜一个权值,k个条件,即第y道菜在第x道后马上吃有z的附加值,求从中取m道菜的最大权值 看到这道题,我们会想到去枚举,但是很显然这是会超时的,再一看数 ...
随机推荐
- 04737_C++程序设计_第10章_面向对象设计实例
10.6.2 使用包含的参考程序及运行结果. 头文件cpp10.h 源文件cpp10.cpp 源文件Find10.cpp 头文件cpp10.h #if ! defined(CPP10_H) #defi ...
- 利用UIScrollView和UIPageControl实现多页图片欢迎页面
在.h文件当中实现UIScrollViewDelegate协议,让控制器充当代理: #import <UIKit/UIKit.h> @interface RPRootViewControl ...
- Radio Link Failure and Recovery
四种会发生Radio Link Failure的场景 - DL Physical Layer Failure (PDCCH BLER > 10%) - Random Access Probl ...
- SQL学习之数据列去空格函数
1.LTRIM()---去掉列值左边的空格 如下代码: select * from dbo.course where tno='t003' and cno='c0013'
- NOPI导出Excel
NOPI导出Excel /// <summary> /// 导出的方法 Excel样式 /// </summary> /// <param name="ds&q ...
- 浅谈SpringMVC(二)
一.SpringMVC的拦截器 1.写类implements HandlerInterceptor public class MyMvcInterceptor implements HandlerIn ...
- C++结构体中sizeof
说明: 结构体的sizeof值,并不是简单的将其中各元素所占字节相加,而是要考虑到存储空间的字节对齐问题.这些问题在平时编程的时候也确实不怎么用到,但在一些笔试面试题目中出是常常出现,一.解释 现代计 ...
- 代码风格——Cocos2d-x学习历程(四)
1.Cocos2d-x拥有一个包含其他所有头文件的文件"cocos2d.h".通常,我们只需要在使用时包含这个头文件,就可以使用引擎的全部功能了. 2.Cocos2d-x的类都放置 ...
- Win8安装ASP.net 4.5(转)
(原文:http://blog.csdn.net/dingxu_ren/article/details/17607451) 今天在我的电脑上部署Web程序时发现页面打不开,网上搜了下是因为先安装的.n ...
- zoj 2071 Technology Trader 最大权闭合子图
传送门 和上一题一样, 也是一个最大权闭合子图.不过建图好麻烦的感觉 写了好久. 源点和原材料连边, 权值为val. 汇点和产品连边, 权值为val. 产品与和它有关系的材料连边, 权值inf. 最 ...