HDU 6006 Engineer Assignment(状压dp)

Engineer Assignment

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1164    Accepted Submission(s): 397


 

Problem Description

In Google, there are many experts of different areas. For example, MapReduce experts, Bigtable experts, SQL experts, etc. Directors need to properly assign experts to various projects in order to make the projects going smoothly.
There are N projects owned by a director. For the ith project, it needs Ci different areas of experts, ai,0,ai,1,⋅⋅⋅,ai,Ci−1 respective. There are M engineers reporting to the director. For the ith engineer, he is an expert of Di different areas, bi,0,bi,1,...,bi,Di−1.
Each engineer can only be assigned to one project and the director can assign several engineers to a project. A project can only be finished successfully if the engineers expert areas covers the project areas, which means, for each necessary area of the project, there is at least one engineer
masters it.
The director wants to know how many projects can be successfully finished.

 

 

Input

The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with a line consisting of 2 integers, N the number of projects and M the number of engineers. Then N lines follow. The ith line containing the information of the ith project starts
with an integer Ci then Ci integers follow, ai,0,ai,1,...,ai,Ci−1 representing the expert areas needed for the ith project. Then another M lines follow. The ith line containing the information of the ith engineer starts with an integer Di then Di integers follow, bi,0,bi,1,...,bi,Di−1 representing the expert areas mastered by ithengineer.

 

 

Output

For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the maximum number of projects can be successfully finished.

limits


∙1≤T≤100.
∙1≤N,M≤10.
∙1≤Ci≤3.
∙1≤Di≤2.
∙1≤ai,j,bi,j≤100.

 

 

Sample Input

 

1 3 4 3 40 77 64 3 10 40 20 3 40 20 77 2 40 77 2 77 64 2 40 10 2 20 77

 

 

Sample Output

 

Case #1: 2

Hint

For the first test case, there are 3 projects and 4 engineers. One of the optimal solution is to assign the first(40 77) and second engineer(77 64) to project 1, which could cover the necessary areas 40, 77, 64. Assign the third(40 10) and forth(20 77) engineer to project 2, which could cover the necessary areas 10, 40, 20. There are other solutions, but none of them can finish all 3 projects. So the answer is 2.

这题唯一的难点就是你是否能想到用状压dp。

题意:

给你n(n<=10)个工程,每个工程需要a[i](a[i]<=3)种能力。给出其需要的能力的编号。m(m<=10)个工程师。每个工程师拥有b[i]种(b[i]<=2)能力,给出其拥有的能力编号。问你怎么安排工程师,使能完成的工程数量最多。

思路:状压dp乱搞就行。我是预处理每个工程师的状态能否完成这项工程,然后三个for枚举每一个工程和分配工程师的状态和能完成这个工程的状态。这题可以说是水题了。

代码:

#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=100010;
int a[15][150];
int c[15][150];
int aa[20],cc[20],n,m;
int jud[1050][15];
int ans,tmp,cnt;
int dp[15][1050];
bool ok[150];
void init()
{
    memset(jud,0,sizeof(jud));
    for(int i=0;i<(1<<m);i++)
    {
        memset(ok,0,sizeof(ok));
        for(int j=1;j<=m;j++)
        if(i&(1<<(j-1))){
            for(int k=1;k<=cc[j];k++)
            ok[c[j][k]]=1;
        }
        for(int j=1;j<=n;j++)
        {
        int k=1;
        for(;k<=aa[j];k++)
        if(!ok[a[j][k]]) break;
        if(k>aa[j]) jud[i][j]=1;
        }
    }
}
int main()
{
    int T,cas=1;
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&n,&m);
        memset(dp,-1,sizeof(dp));
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&aa[i]);
            for(int j=1;j<=aa[i];j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        for(int i=1;i<=m;i++)
        {
            scanf("%d",&cc[i]);
            for(int j=1;j<=cc[i];j++)
            {
                scanf("%d",&c[i][j]);
            }
        }
        init();
        int nn=(1<<m);
        ans=0;
        dp[0][0]=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<nn;j++)
            {
                dp[i][j]=max(dp[i][j],dp[i-1][j]);
                for(int k=0;k<nn;k++)
                if(!(k&j)&&jud[k][i]){
                    dp[i][j|k]=max(dp[i][j|k],dp[i-1][j]+1);
                }
            }
        }
        ans=0;
        for(int i=1;i<=n;i++)
        for(int j=0;j<nn;j++)
        ans=max(ans,dp[i][j]);
        printf("Case #%d: %d\n",cas++,ans);
    }
    return 0;
}

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值