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 ...
随机推荐
- Overlapped I/O模型深入分析(转)
随笔 - 262 文章 - 0 评论 - 531 博客园 首页 新随笔 联系 管理 订阅 Overlapped I/O模型深入分析(转) 简述: Overlapped I/O也 ...
- android 自己定义组合控件
自己定义控件是一些android程序猿感觉非常难攻破的难点,起码对我来说是这种,可是我们能够在网上找一些好的博客关于自己定义控件好好拿过来学习研究下,多练,多写点也能找到感觉,把一些原理弄懂,今天就讲 ...
- PHP代码优化之细节优化(转)
PHP 独特的语法混合了 C.Java.Perl 以及 PHP 自创新的语法.它可以比 CGI或者Perl更快速的执行动态网页.用PHP做出的动态页面与其他的编程语言相比,PHP是将程序嵌入到HTML ...
- C#处理和对接HTTP接口请求
对于现在接口泛滥的时代,了解和处理接口对于一名程序员来说是很有必要的! 在对接时对于对方发过来的文档,需要认真看一遍,有疑问的比如加密等,需特别提出来和对方交接: 第一步,在对接接口时,你应该拿到服务 ...
- POJ 2750 Potted Flower (单点改动求线段树上最大子序列和)
题目大意: 在一个序列上每次改动一个值,然后求出它的最大的子序列和. 思路分析: 首先我们不考虑不成环的问题.那就是直接求每一个区间的最大值就好了. 可是此处成环,那么看一下以下例子. 5 1 -2 ...
- xml去除指定节点,保留子节点操作
现有xml文件: <?xml version="1.0" encoding="utf-8" ?> <ShiftConfig xmlns:xsi ...
- 让 Node.js 支持 ES6 的语法
为了让 Node.js 支持 ES6 的语法, 需要使用 Babel. 安装 es-checker 在使用 Babel 之前 , 我们先检测一下当前 node 对 es6 的支持情况. 在命令行下执行 ...
- Spring Boot构建RESTful API
@Controller:修饰class,用来创建处理http请求的对象 @RestController:Spring4之后加入的注解,原来在@Controller中返回json需要@ResponseB ...
- location 禁止多目录
[root@web01 default]# mkdir cron templates [root@web01 default]# tree . ├── cron └── templates direc ...
- redmine 的安装
https://bitnami.com/stack/redmine/installer#官方地址 安装很简单,给权限 chmod +x bitnami-redmine-3.3.0-1-linux-x6 ...