Engineer Assignment

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

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个项目,每个项目涉及到最多3个不同的领域,有m个工程师每个工程师掌握最多两个不同的领域,每个工程师只能参与一个项目,问最多能完成几个项目。(数据范围)

代码:

//把工程师状压然后枚举处理到第i个项目所用的状态j,然后如果做第i个项目那么再枚举k状态来完成i项目,j^k状态处理前i-1的项目,这样再加上
//100组样例就超时了,可以预处理出来每一个项目可以用那些状态来完成,所以第三层循环最多120个。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int t,n,m,f[][],a[][],b[][],sol[][];
bool vis[],has[][];
void get_has()
{
for(int i=;i<(<<);i++){
for(int j=;j<(<<);j++){
has[i][j]=;
for(int k=;k<;k++){
if(!(i&(<<k))&&(j&(<<k))) has[i][j]=;
}
}
}
}
bool check(int sta,int x)
{
memset(vis,,sizeof(vis));
vis[]=;
for(int i=;i<m;i++){
if(sta&(<<i)){
vis[a[i][]]=vis[a[i][]]=;
}
}
if(vis[b[x][]]&&vis[b[x][]]&&vis[b[x][]]) return ;
return ;
}
void get_sol()
{
for(int i=;i<=n;i++){
sol[i][]=;
for(int j=;j<(<<m);j++){
if(check(j,i)){
sol[i][]++;
sol[i][sol[i][]]=j;
}
}
}
}
int main()
{
get_has();
scanf("%d",&t);
for(int cas=;cas<=t;cas++){
memset(a,,sizeof(a));
memset(b,,sizeof(b));
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
int x;
scanf("%d",&x);
for(int j=;j<x;j++) scanf("%d",&b[i][j]);
}
for(int i=;i<m;i++){
int x;
scanf("%d",&x);
for(int j=;j<x;j++) scanf("%d",&a[i][j]);
}
get_sol();
memset(f,,sizeof(f));
for(int i=;i<=n;i++){
for(int j=;j<(<<m);j++){
f[i][j]=max(f[i][j],f[i-][j]);
for(int k=;k<=sol[i][];k++){
if(!has[j][sol[i][k]]) continue;
f[i][j]=max(f[i][j],f[i-][j^sol[i][k]]+);
}
}
}
printf("Case #%d: %d\n",cas,f[n][(<<m)-]);
}
return ;
}

HDU 6006 状压dp的更多相关文章

  1. Engineer Assignment HDU - 6006 状压dp

    http://acm.split.hdu.edu.cn/showproblem.php?pid=6006 比赛的时候写了一个暴力,存暴力,过了,还46ms 那个暴力的思路是,预处理can[i][j]表 ...

  2. HDU 4778 状压DP

    一看就是状压,由于是类似博弈的游戏.游戏里的两人都是绝对聪明,那么先手的选择是能够确定最终局面的. 实际上是枚举最终局面情况,0代表是被Bob拿走的,1为Alice拿走的,当时Alice拿走且满足变换 ...

  3. HDU 3001 状压DP

    有道状压题用了搜索被队友骂还能不能好好训练了,, hdu 3001 经典的状压dp 大概题意..有n个城市 m个道路  成了一个有向图.n<=10: 然后这个人想去旅行.有个超人开始可以把他扔到 ...

  4. hdu 2809(状压dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2809 思路:简单的状压dp,看代码会更明白. #include<iostream> #in ...

  5. hdu 2167(状压dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2167 思路:经典的状压dp题,前后,上下,对角8个位置不能取,状态压缩枚举即可所有情况,递推关系是为d ...

  6. hdu 3254 (状压DP) Corn Fields

    poj 3254 n乘m的矩阵,1表示这块区域可以放牛,0,表示不能,而且不能在相邻的(包括上下相邻)两个区域放牛,问有多少种放牛的方法,全部不放也是一种方法. 对于每块可以放牛的区域,有放或者不放两 ...

  7. HDU 5823 (状压dp)

    Problem color II 题目大意 定义一个无向图的价值为给每个节点染色使得每条边连接的两个节点颜色不同的最少颜色数. 对于给定的一张由n个点组成的无向图,求该图的2^n-1张非空子图的价值. ...

  8. hdu 4739 状压DP

    这里有状态压缩DP的好博文 题目:题目比较神,自己看题目吧 分析: 大概有两种思路: 1.dfs,判断正方形的话可以通过枚举对角线,大概每次减少4个三角形,加上一些小剪枝的话可以过. 2.状压DP,先 ...

  9. Travel(HDU 4284状压dp)

    题意:给n个城市m条路的网图,pp在城市1有一定的钱,想游览这n个城市(包括1),到达一个城市要一定的花费,可以在城市工作赚钱,但前提有工作证(得到有一定的花费),没工作证不能在该城市工作,但可以走, ...

随机推荐

  1. 模块-Memcached、Redis

    目录 Mecache 安装 使用 Redis 安装 Python操作Redis 操作模式 连接池 操作 String Hash List Set sort set 其他常用操作 管道 发布订阅 sen ...

  2. java工程文件路径的问题

    String classpath = this.getClass().getResource("/").getPath().replaceFirst("/WEB-INF/ ...

  3. Thunder——Final冲刺中间产物

    版本控制: http://www.cnblogs.com/lick468/p/7994015.html 软件功能说明书: http://www.cnblogs.com/szjzsd/p/7979565 ...

  4. Daily Scrumming* 2015.10.30(Day 11)

    一.总体情况总结 今日项目总结: 1.前后端同一了API设计以及API权限认证.用户状态保存的开发方案 2.API以及后端模型已经开始开发,前端UEditor开始学习,本周任务有良好的起步 3.前后端 ...

  5. Linux 读书笔记 三 (第二章)

      一.学习目标 1. 理解二进制在计算机中的重要地位 2. 掌握布尔运算在C语言中的应用 3. 理解有符号整数.无符号整数.浮点数的表示 4. 理解补码的重要性 5. 能避免C语言中溢出,数据类型转 ...

  6. oracle 语句之对数据库的表名就行模糊查询,对查询结果进行遍历,依次获取每个表名结果中的每个字段(存储过程)

    语句的执行环境是plsql的sql窗口, 语句的目的是从整个数据库中的所有表判断 不等于某个字段的记录数 . 代码如下: declare s_sql clob:=''; -- 声明一个变量,该变量用于 ...

  7. mybatis连接数据库的几种方式

    1.可以通过配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="ht ...

  8. 【动态规划】POJ-2385

    一.题目 Description It is a little known fact that cows love apples. Farmer John has two apple trees (w ...

  9. PROFIBUS-DP现场总线的结构及应用

    PROFIBUS的最大优点在于具有稳定的国际标准EN50170作保证,并经实际应用验证具有普遍性.目前已广泛应用于制造业自动化.流程工业自动化和楼宇.交通电力等领域. PROFIBUS由3个兼容部分组 ...

  10. Excelutil 工具类

    1.说明:ExcelUtil主要用于获得单元格的数据和对对指定单元格中写入数据用! 相关代码如下: package main.java; import java.io.File; import jav ...