Codeforces 417 D. Cunning Gena
按monitor排序,然后状压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 thei-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
#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的更多相关文章
- 【codeforces 417D】Cunning Gena
[题目链接]:http://codeforces.com/problemset/problem/417/D [题意] 有n个人共同完成m个任务; 每个人有可以完成的任务集(不一定所有任务都能完成); ...
- Codeforces 417D Cunning Gena(状态压缩dp)
题目链接:Codeforces 417D Cunning Gena 题目大意:n个小伙伴.m道题目,每一个监视器b花费,给出n个小伙伴的佣金,所须要的监视器数,以及能够完毕的题目序号. 注意,这里仅仅 ...
- Cunning Gena CodeForces - 417D
Cunning Gena CodeForces - 417D 题意 先将小伙伴按需要的监视器数量排序.然后ans[i][j]表示前i个小伙伴完成j集合内题目所需最少钱.那么按顺序枚举小伙伴,用ans[ ...
- codeforces 417D. Cunning Gena 状压dp
题目链接 D. Cunning Gena time limit per test 1 second memory limit per test 256 megabytes input standard ...
- FZU 2165 v11(最小重复覆盖)+ codeforces 417D Cunning Gena
告诉你若干个(<=100)武器的花费以及武器能消灭的怪物编号,问消灭所有怪物(<=100)的最小花费...当然每个武器可以无限次使用,不然这题就太水了╮(╯▽╰)╭ 这题当时比赛的时候连题 ...
- Codeforces 417 C
Football Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...
- RCC 2014 Warmup (Div. 2) 蛋疼解题总结
A. Elimination time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 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 ...
- 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 ...
随机推荐
- 基于canvas的原生JS时钟效果
概述 运用html5新增画布canvas技术,绘制时钟效果,无需引用任何插件,纯js. 详细 代码下载:http://www.demodashi.com/demo/11935.html 给大家介绍一个 ...
- tsung的配置使用
1.在root下新建.tsung文件,在.tsung文件新建log文件夹..tsung文件用于存放log和xml文件 2.复制/usr/local/tsung/share/doc/tsung/exam ...
- .NET资料之-根据两点经纬度计算直线距离
最近做东西碰到要根据两点经纬度计算之间的直线距离,就网上找了查了下资料.因为这类接触的比较少,就直接找现成的代码了,没怎么研究.代码如下,作为记录. private const double EART ...
- SQL 关于apply的两种形式cross apply 和 outer apply, with cube 、with rollup 和 grouping
1). apply有两种形式: cross apply 和 outer apply先看看语法: <left_table_expression> {cross|outer} apply &l ...
- java中成员变量、代码块、构造函数运行顺序
1.java虚拟机执行程序,首先须要装载类,安装现装载父类,初始化父类的静态代码块和静态成员变量 再load子类. 初始化子类静态代码块和成员变量 2.load完成父类与子类后,从main函数入口运行 ...
- Atitit.js javascript异常处理机制与java异常的转换.js exception process Voae
Atitit.js javascript异常处理机制与java异常的转换.js exception processVoae 1. 1. javascript异常处理机制 1 2. 2. Web前后台异 ...
- CentOS6.x和CentOS7.X启动系统不显示进度条设置方法
[root@ok Desktop]# vi /boot/grub/grub.conf # grub.conf generated by anaconda # # Note that you do no ...
- html中iframe子页面与父页面元素的访问以及js变量的访问
1.子页面访问父页面元素 parent.document.getElementById('id')和document相关的方法都可以这样用 2.父页面访问子页面元素 document.ge ...
- 每日英语:Vender Assault Shines Ugly Light on China's Urban Enforcers
The sudden death of a street vendor in Hunan province on Wednesday provoked outrage chengguan, or ur ...
- ELK-“线上标准文档”——测试
Elasticstack官网:https://www.elastic.co 本文档仅限搭建过程参考,使用相关的文档,不在本文档讨论范围之内. 一切依据的核心即是Elasticstack官网. 查看支持 ...