CF417D--- Cunning Gena(序列+像缩进dp)
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)的更多相关文章
- codeforces 417D. Cunning Gena 状压dp
题目链接 D. Cunning Gena time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 417D Cunning Gena(状态压缩dp)
题目链接:Codeforces 417D Cunning Gena 题目大意:n个小伙伴.m道题目,每一个监视器b花费,给出n个小伙伴的佣金,所须要的监视器数,以及能够完毕的题目序号. 注意,这里仅仅 ...
- Codeforces 417 D. Cunning Gena
按monitor排序,然后状压DP... . D. Cunning Gena time limit per test 1 second memory limit per test 256 megaby ...
- HDU 3681 BFS&像缩进DP&二分法
N*M矩阵.从F出发点.走完全部Y点.每个人格开支1电源点,去G点,电池充满,D无法访问.最小的开始问什么时候满负荷可以去完全部Y.Y和G总共高达15一 第一BFS所有的F.Y.G之间的最短距离. 然 ...
- 括号序列(区间dp)
括号序列(区间dp) 输入一个长度不超过100的,由"(",")","[",")"组成的序列,请添加尽量少的括号,得到一 ...
- Cunning Gena CodeForces - 417D
Cunning Gena CodeForces - 417D 题意 先将小伙伴按需要的监视器数量排序.然后ans[i][j]表示前i个小伙伴完成j集合内题目所需最少钱.那么按顺序枚举小伙伴,用ans[ ...
- 区间和序列上的dp
区间上的dp状态设计最基本的形式: \(F[i]\)表示以i结尾的最优值或方案数. \(F[i][k]\)表示以i结尾附加信息为k的最优值或方案数. 当然可以有多维附加信息. 转移的话往往是枚举上一个 ...
- bzoj4032/luoguP4112 [HEOI2015]最短不公共子串(后缀自动机+序列自动机上dp)
bzoj4032/luoguP4112 [HEOI2015]最短不公共子串(后缀自动机+序列自动机上dp) bzoj Luogu 题解时间 给两个小写字母串 $ A $ , $ B $ ,请你计算: ...
- Easy 2048 Again - ZOJ 3802 像缩进dp
Easy 2048 Again Time Limit: 2 Seconds Memory Limit: 65536 KB Dark_sun knows that on a single-tr ...
随机推荐
- [Cocos2d-x]CCSpriteFrameCache的使用
文档: http://cocos2d.cocoachina.com/document/index/class?url=dc/dda/classcocos2d_1_1_c_c_sprite_frame_ ...
- mmap。
linux mmap 内存映射 mmap() vs read()/write()/lseek() 通过strace统计系统调用的时候,常常能够看到mmap()与mmap2().系统调用mmap()能够 ...
- Invalid embedded descriptor for ".proto".Dependencies passed (Protobufer)解决办法
前言 之前开发的时候,发现居然出现了Dependencies passed to FileDescriptor.buildFrom() don't match those listed in the ...
- myeclipse 那个版本号好用?
myeclipse 那个版本号好用? 有没有现成的下载地址?
- 启动和关闭JBoss As 7.1.1脚本
启动和关闭JBoss As 7.1.1,脚本例如以下djboss.sh: #!/bin/sh #JBOSS_HOME JBOSS_HOME=/opt/jboss case "$1" ...
- cocos2D(四)---- CCSprite
在介绍CCSprite之前,先要理解游戏开发中的一个核心概念:精灵.精灵也称为游戏对象,它能够用来表示游戏中的不论什么物体,比方敌人.子弹.甚至是一个背景图片.一段文字.CCSprite能够说是在co ...
- poj3295 Tautology , 计算表达式的值
给你一个表达式,其包括一些0,1变量和一些逻辑运算法,让你推断其是否为永真式. 计算表达式的经常使用两种方法:1.递归: 2.利用栈. code(递归实现) #include <cstdio&g ...
- SQLServer 复制和数据库镜像 具体配置部署
SQLserver 能够把镜像和复制同一时候部署,结合了两方的高可用性.能够使数据库得到更好的高可用性和容灾的保证. 关于镜像:f=255&MSPPError=-2147217396" ...
- JAVA 计算地球上任意两点(经纬度)距离
/** * 计算地球上任意两点(经纬度)距离 * * @param long1 * 第一点经度 * @param lat1 * 第一点纬度 * @param long2 * 第二点经度 * @para ...
- poj1804(归并排序求逆序数)
逆序数.也就是说,对于n个不同的元素,先规定各元素之间有一个标准次序(比如n个 不同的自然数,可规定从小到大为标准次序),于是在这n个元素的任一排列中,当某两个元素的先后次序与标准次序不同一时候,就说 ...