RCC 2014 Warmup (Div. 2) D. Cunning Gena(状压DP)

185 篇文章 0 订阅
96 篇文章 0 订阅

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 nm and b (1 ≤ n ≤ 1001 ≤ m ≤ 201 ≤ 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 xiki and mi (1 ≤ xi ≤ 1091 ≤ ki ≤ 1091 ≤ 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.

Output

Print the minimum amount of money Gena needs to spend to solve all the problems. Or print -1, if this cannot be achieved.

Examples
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(<20)个题目需要解决,你有m个朋友可以求助,第i个朋友可以解决指定的mi道题目,花费为xi卢布,并且要求你至少拥有ki个显示器,每个显示器b卢布,问需要解决所有题目的最小花费。

分析:状压dp,直接压现在已经解决的题目的集合,需要思考的问题是对于每个朋友所需的显示器个数不同,这个其实只要把所有朋友按显示器个数排序枚举就行了。

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<queue>
#define INF 4557430888798830400ll
#define eps 1e-9
#define MAXN 0x3f
#define N 20
using namespace std;
int n,m,t,b;
unsigned long long ans,dp[1<<20];
struct thing
{
	int x,k,m,sta;
	friend bool operator < (thing a,thing b)
	{
		return a.k < b.k;
	}
}p[105];
int main()
{
	scanf("%d%d%d",&n,&m,&b);
	for(int i = 1;i <= n;i++)
	{
		scanf("%d%d%d",&p[i].x,&p[i].k,&p[i].m);
		for(int j = 1;j <= p[i].m;j++)	
		{
			scanf("%d",&t);
			p[i].sta += 1<<(t-1);
		}
	} 
	sort(p+1,p+1+n);
	memset(dp,MAXN,sizeof(dp));
	dp[0] = 0,ans = INF;
	for(int i = 1;i <= n;i++)
	{
		for(int j = (1<<m)-1;j >= 0;j--)
	 	 if(dp[j] < INF) dp[j | p[i].sta] = min(dp[j | p[i].sta],dp[j] + p[i].x);
	 	ans = min(ans,dp[(1<<m)-1] + 1ll*p[i].k * b);
	}
	if(ans < INF) cout<<ans<<endl;
	else cout<<-1<<endl;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值