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 ...
随机推荐
- 图像处理特征不变算子系列之Moravec算子(一)
论文转载请注明出处:http://blog.csdn.net/kezunhai 1977年,Moravec提出了兴趣点(Points of Interests)的概念,并应用于解决Stanford C ...
- python—webshell_醉清风xf_新浪博客
python—webshell_醉清风xf_新浪博客 python—webshell (2012-05-23 09:55:46) 转载▼
- Linux中下载,压缩,解压等命令
查看是否和还有一台Linux机器相通命令:ssh 主机名@Ip地址 ,提示输入password.就可以查看远程文件的文件夹 下载远程机器上的文件:scp 主机名@Ip地址:/path/s ...
- H3C TE老版本OSPF正确配置
R1配置: ---------------------------------------------------- # sysname RT1# super password level 3 cip ...
- Linux 命令学习之dpkg命令详解
dpkg是一个Debian的一个命令行工具,它可以用来安装.删除.构建和管理Debian的软件包. 下面是它的一些命令解释: 1)安装软件 命令行:dpkg -i <.deb file name ...
- jar包有嵌套的jar的打包成jar的方法
1.先写一个类,将其打包成jar包. 代码如下: package com.wjy.jar; public class GetUserName { public String getUserName() ...
- 推测的手机型号和cpu模型
<span style="font-size:18px;">推断手机型号:</span> <span style="font-size:18 ...
- 数据库采用多表连接查询,对应javaBean文件连接方式
在一个Web项目中,只要是存在数据库就一定会有JavaBean文件.一个JavaBean文件会对应一张数据库中的表,供dao中的代码来调用用来存取数据.我们都知道,在数据库设计的时候,如果A.B两张表 ...
- TextBox自定义Mac输入框类
using System.Windows.Controls; namespace test { public class MacTextBox : TextBox { private string _ ...
- windows phone 7 定位(获取经纬度),然后找到经纬度所在的位置(城市信息)
原文:windows phone 7 定位(获取经纬度),然后找到经纬度所在的位置(城市信息) 前几天做项目用到, 代码贴给大家. /// <summary> /// 获取当前位置的经纬度 ...