Engineer Assignment

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

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.

 
Source

题意:给你一些N个地点,每个地点有多个种类问题,M个工程师,一个工程可以解决一些问题;求最多解决几个;

思路:状态压缩dp;

   dp[i][j]表示解决前i个,用状态压缩的使用了j的工程师,最多解决问题数;

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<bitset>
#include<time.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-8
#define bug(x) cout<<"bug"<<x<<endl;
const int N=+,M=1e6+,inf=1e9+,MOD=1e9+;
const LL INF=1e18+,mod=1e9+; struct Hash
{
int flag[],tot;
void init()
{
memset(flag,,sizeof(flag));
tot=;
}
int operator [](int x)
{
if(flag[x])return flag[x];
flag[x]=++tot;
return flag[x];
}
}f;
LL a[N],b[N];
int dp[N][];
int check(int pos,int x,int y,int m)
{
LL ans=;
for(int i=;i<=m;i++)
{
LL xx=(1LL<<(i-))&x;
LL zz=(1LL<<(i-))&y;
if(xx^zz)
{
ans|=b[i];
}
}
if((ans|a[pos])==ans)return ;
return ;
}
int main()
{
int T,cas=;
scanf("%d",&T);
while(T--)
{
f.init();
memset(a,,sizeof(a));
memset(b,,sizeof(b));
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
int t;
scanf("%d",&t);
while(t--)
{
int x;
scanf("%d",&x);
a[i]|=(1LL<<(f[x]-));
}
}
for(int i=;i<=m;i++)
{
int t;
scanf("%d",&t);
while(t--)
{
int x;
scanf("%d",&x);
b[i]|=(1LL<<(f[x]-));
}
}
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
{
for(int j=;j<=(<<m)-;j++)
{
for(int k=;k<=j;k++)
{
if((k|j)!=j)continue;
dp[i][j]=max(dp[i][j],dp[i-][k]+check(i,j,k,m));
}
}
}
printf("Case #%d: %d\n",cas++,dp[n][(<<m)-]);
}
return ;
}

hdu 6006 Engineer Assignment 状压dp的更多相关文章

  1. HDU - 6006 Engineer Assignment (状压dfs)

    题意:n个工作,m个人完成,每个工作有ci个阶段,一个人只能选择一种工作完成,可以不选,且只能完成该工作中与自身标号相同的工作阶段,问最多能完成几种工作. 分析: 1.如果一个工作中的某个工作阶段没有 ...

  2. HDU6006:Engineer Assignment(状压DP)

    传送门 题意 给出n个工程,m个工程师,每个工程和工程师需要/拥有若干个技能,询问能够完成的最大工程个数,每个工程师用一次 分析 dp[i][j]表示前i个工程用的工程师集合为j的最大工程个数,那么有 ...

  3. hdu 3247 AC自动+状压dp+bfs处理

    Resource Archiver Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Ot ...

  4. hdu 2825 aC自动机+状压dp

    Wireless Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  5. HDU 5765 Bonds(状压DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5765 [题目大意] 给出一张图,求每条边在所有边割集中出现的次数. [题解] 利用状压DP,计算不 ...

  6. hdu 3681(bfs+二分+状压dp判断)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 思路:机器人从出发点出发要求走过所有的Y,因为点很少,所以就能想到经典的TSP问题.首先bfs预 ...

  7. hdu 4778 Gems Fight! 状压dp

    转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...

  8. hdu 4856 Tunnels (bfs + 状压dp)

    题目链接 The input contains mutiple testcases. Please process till EOF.For each testcase, the first line ...

  9. HDU 4272 LianLianKan (状压DP+DFS)题解

    思路: 用状压DP+DFS遍历查找是否可行.假设一个数为x,那么他最远可以消去的点为x+9,因为x+1~x+4都能被他前面的点消去,所以我们将2进制的范围设为2^10,用0表示已经消去,1表示没有消去 ...

随机推荐

  1. openssh-win64 on windows2016 ssh pub key config

    DO NOT follow the official M$ documentation at https://docs.microsoft.com/en-us/windows-server/admin ...

  2. Redis考察点解析

    目录 1. Redis数据结构 1. 常用数据结构 2. 高级数据结构 2. Redis分布式锁 1. Redis分布式锁原理 2. 如果在setnx之后执行expire之前进程意外crash或者要重 ...

  3. _sntprintf_s 和 _sntprintf 区别

    https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/snprintf-s-snprintf-s-l-snwprintf-s ...

  4. Mac截图操作,自定义快捷键

    选择system preferences 下面能看到系统定义的快捷键,可以自己修改

  5. Vue一、起步

    1.参考资料-官网 https://cn.vuejs.org/v2/guide/ 2.介绍 Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架 与其它大型框架不同,V ...

  6. 用原生js+canvas实现五子棋

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  7. 使用JavaScript实现单向链表

    一.实现功能 1.链表元素头部插入 this.unShift = function(data) {} 2.链表元素尾部插入 this.append= function(data) {} //返回boo ...

  8. Go 初体验 - 错误与异常处理 - recover和panic

    先看代码: 输出: 内建函数panic可以让我们人为地产生一个运行时恐慌.不过,这种致命错误是可以被恢复的.在Go语言中,内建函数recover就可以做到这一点. 实际上,内建函数panic和reco ...

  9. c# ASP.NET Core2.2利用中间件支持跨域请求

    1.public void Configure(IApplicationBuilder app, IHostingEnvironment env)方法里面 不要加上:app.UseCors(); 2. ...

  10. 学Python的感受

    这门课程已经上了两周了,虽然还没学到什么实质上的东西,只是做了几道题,但是我也感受到了Python的魅力.我感觉这门课真的很有用,比如老师所说的网络爬虫,我对这个非常感兴趣.再说说老师的教学方式,理论 ...