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

分析:

1、如果一个工作中的某个工作阶段没有任何一个人能完成,则这个工作是不可完成的。

2、预处理每个人能完成各工作的各工作阶段。

3、剪枝:如果当前完成工作数+剩余人数<=ans则剪枝。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 10 + 10;
const int MAXT = 10000 + 10;
using namespace std;
vector<int> t[MAXN], project[MAXN];
vector<int> engineer[MAXN];
int status[MAXN];
int work[MAXN][MAXN];
int ans;
int n, m;
map<int, int> mp;
int projectnum;
void dfs(int cur, int done){
if(done + m - (cur - 1) <= ans) return;
if(cur == m + 1){
ans = max(ans, done);
return;
}
dfs(cur + 1, done);
for(int i = 1; i <= projectnum; ++i){
int len = project[i].size();
if(status[i] == (1 << len) - 1) continue;
int tmp = status[i];
status[i] |= work[cur][i];
if(status[i] == (1 << len) - 1){
dfs(cur + 1, done + 1);
}
else{
dfs(cur + 1, done);
}
status[i] = tmp;
}
}
void have(int x, int y){
int len1 = engineer[x].size();
int len2 = project[y].size();
for(int i = 0; i < len2; ++i){
bool ok = false;
for(int j = 0; j < len1; ++j){
if(engineer[x][j] == project[y][i]){
ok = true;
break;
}
}
if(ok) work[x][y] |= (1 << i);
}
}
int main(){
int T;
scanf("%d", &T);
int kase = 0;
while(T--){
mp.clear();
ans = 0;
for(int i = 0; i < MAXN; ++i){
project[i].clear();
engineer[i].clear();
t[i].clear();
}
memset(work, 0, sizeof work);
memset(status, 0, sizeof status);
scanf("%d%d", &n, &m);
int k, x;
for(int i = 1; i <= n; ++i){
scanf("%d", &k);
for(int j = 0; j < k; ++j){
scanf("%d", &x);
t[i].push_back(x);
}
}
for(int i = 1; i <= m; ++i){
scanf("%d", &k);
for(int j = 0; j < k; ++j){
scanf("%d", &x);
mp[x] = 1;
engineer[i].push_back(x);
}
}
projectnum = 0;
for(int i = 1; i <= n; ++i){
int l = t[i].size();
bool ok = true;
for(int j = 0; j < l; ++j){
if(!mp.count(t[i][j])){
ok = false;
break;
}
}
if(ok) project[++projectnum] = t[i];
}
for(int i = 1; i <= m; ++i){
for(int j = 1; j <= projectnum; ++j){
have(i, j);
}
}
dfs(1, 0);
printf("Case #%d: %d\n", ++kase, ans);
}
return 0;
}

  

HDU - 6006 Engineer Assignment (状压dfs)的更多相关文章

  1. hdu 6006 Engineer Assignment 状压dp

    Engineer Assignment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  2. HDU 6006 Engineer Assignment:状压dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6006 题意: 在Google中,有个n项目,m个专家.第i个项目涉及c[i]个领域,分别为a[i][0 ...

  3. HDU6006:Engineer Assignment(状压DP)

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

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

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

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

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

  6. ZOJ 1609 Equivalence(状压+dfs减枝)

    ZOJ Problem Set - 1609 Equivalence Time Limit: 5 Seconds      Memory Limit: 32768 KB When learning m ...

  7. bzoj1725: [Usaco2006 Nov]Corn Fields牧场的安排(状压dfs)

    1725: [Usaco2006 Nov]Corn Fields牧场的安排 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1122  Solved: 80 ...

  8. 状压dfs小记

    一点前(tu)言(cao) 真的考起dfs来可谓是什么都能往dfs上套 状压不止能dp,还能与dfs结合成为搜索好(duliu)题 剪枝卡常司空见惯(打开题解一看并不是纯dfs,emmmm) 开始正文 ...

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

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

随机推荐

  1. 微信小程序引用外部js,引用外部样式,引用公共页面模板

    https://blog.csdn.net/smartsmile2012/article/details/83414642 ================小程序引用外部js============= ...

  2. myBatis mapper接口方法重载问题

    在mybatis框架中,写dao层的mapper接口时,是不可以进行方法的重载的,下面是截图证明:   当mapper接口中有方法的重载时,会出现异常,   这是mapper接口中定义的两个方法,进行 ...

  3. underscore.js -2009年发布的js库

    2009 Underscore.js 0.1.0发布 Underscore一个JavaScript实用库,提供了一整套函数式编程的实用功能,但是没有扩展任何JavaScript内置对象.它是这个问题的 ...

  4. 128、Java面向对象之对象的比较

    01.代码如下: package TIANPAN; class Book { private String title; private double price; public Book(Strin ...

  5. MVC webuploader 图片

    AARTO:SaveNoticeAndDocument ~/Scripts/Upload/webuploader-0.1.4/dist/webuploader.js

  6. scrapy(创建scrapy工程)报错:“ ImportError:DLL load failed:找不到指定的模块”

    先要确定什么模块找不到 解决方法 windowa环境下加 ( --user) pip install -I cryptography --user

  7. Codeforces 1196D2 RGB Substring (Hard version) 题解

    题面 \(q\) 个询问,每个询问给出一个字符串 \(s\),要你在 \(s\) 中用最小替换得到无穷字符串 RGBRGBRGB... 的长度为定值 \(k\) 的子串. 题解 一眼看过去可能是编辑距 ...

  8. CyclicBarrier 解读

    简介 字面上的意思: 可循环利用的屏障. 作用: 让所有线程都等待完成后再继续下一步行动. 举例模拟: 吃饭人没到齐不准动筷. 使用Demo package com.ronnie; import ja ...

  9. 夯实Java基础(十八)——泛型

    1.什么是泛型 泛型是Java1.5中出现的新特性,也是最重要的一个特性.泛型的本质是参数化类型,也就是说所操作的数据类型被指定为一个参数.这种参数类型可以用在类.接口和方法的创建中,分别称为泛型类. ...

  10. Acwing897 最长公共子序列

    题目大意:求两个字符串的最长公共子序列的长度. 分析:这是一个典型的dp入门题,LCS. 代码: #include<bits/stdc++.h> using namespace std; ...