codefoces 417D Cunning Gena 状压DP

21 篇文章 1 订阅

题目链接:cf 417D

        一个人有m道题要做,他自己不会做,有n个人可以让他选来帮他做,给出每个人可做的题,让他做题至少需要的显示器数目,以及雇他做题的代价,每个显示器需要花费b的代价,问做完所有题的代价最小是多少。
m的范围最大只有20,因此假如不考虑显示器的代价,这道题就是标准的状压DP了
多了个显示器的条件,只需要把人按显示器的需要量从小到大排序,然后做标准的状压DP,DP时不要考虑显示器的代价,求出当前的可行解,然后加上当前人的显示器的需要量的代价即可。

/******************************************************
 * File Name:   417d.cpp
 * Author:      kojimai
 * Creater Time:2014年08月25日 星期一 10时02分00秒
******************************************************/

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
long long dp[1<<20];//表示做出当前状态下所有题的最小雇佣代价
struct node
{
	int x;//雇佣代价
	int k;//所要的显示器的数目
	int state;//二进制表示出可做题的状态
}fr[105];
bool cmp(node a,node b)
{
	return a.k<b.k;
}
int main()
{
	int n,m,num;
	int b;
	cin>>n>>m>>b;
	for(int i=0;i<n;i++)
	{
		cin>>fr[i].x>>fr[i].k>>num;
		//scanf("%d%d%d",&fr[i].x,&fr[i].k,&num);
		fr[i].state=0;
		int y;
		while(num--)
		{
			scanf("%d",&y);
			fr[i].state+=(1<<(y-1));
		}
	}
	memset(dp,-1,sizeof(dp));
	sort(fr,fr+n,cmp);
	int all=(1<<m);
	long long ans=-1,tmp;
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<all;j++)
		{
			if(dp[j]==-1)
				continue;
			int st=fr[i].state|j;
			if(dp[st]==-1)
				dp[st]=dp[j]+fr[i].x;
			else
				dp[st]=min(dp[st],dp[j]+fr[i].x);
		}
		if(dp[all-1]!=-1)
		{
			tmp=((long long)fr[i].k)*b+dp[all-1];
			if(ans==-1)
				ans=tmp;
			else
				ans=min(tmp,ans);
		}
		//cout<<"i="<<i<<" dp[all-1]="<<dp[all-1]<<endl;
	}
	cout<<ans<<endl;
	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值