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

分析:

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

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

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

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cstdlib>
  4. #include<cctype>
  5. #include<cmath>
  6. #include<iostream>
  7. #include<sstream>
  8. #include<iterator>
  9. #include<algorithm>
  10. #include<string>
  11. #include<vector>
  12. #include<set>
  13. #include<map>
  14. #include<stack>
  15. #include<deque>
  16. #include<queue>
  17. #include<list>
  18. #define lowbit(x) (x & (-x))
  19. const double eps = 1e-8;
  20. inline int dcmp(double a, double b){
  21. if(fabs(a - b) < eps) return 0;
  22. return a > b ? 1 : -1;
  23. }
  24. typedef long long LL;
  25. typedef unsigned long long ULL;
  26. const int INT_INF = 0x3f3f3f3f;
  27. const int INT_M_INF = 0x7f7f7f7f;
  28. const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
  29. const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
  30. const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
  31. const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
  32. const int MOD = 1e9 + 7;
  33. const double pi = acos(-1.0);
  34. const int MAXN = 10 + 10;
  35. const int MAXT = 10000 + 10;
  36. using namespace std;
  37. vector<int> t[MAXN], project[MAXN];
  38. vector<int> engineer[MAXN];
  39. int status[MAXN];
  40. int work[MAXN][MAXN];
  41. int ans;
  42. int n, m;
  43. map<int, int> mp;
  44. int projectnum;
  45. void dfs(int cur, int done){
  46. if(done + m - (cur - 1) <= ans) return;
  47. if(cur == m + 1){
  48. ans = max(ans, done);
  49. return;
  50. }
  51. dfs(cur + 1, done);
  52. for(int i = 1; i <= projectnum; ++i){
  53. int len = project[i].size();
  54. if(status[i] == (1 << len) - 1) continue;
  55. int tmp = status[i];
  56. status[i] |= work[cur][i];
  57. if(status[i] == (1 << len) - 1){
  58. dfs(cur + 1, done + 1);
  59. }
  60. else{
  61. dfs(cur + 1, done);
  62. }
  63. status[i] = tmp;
  64. }
  65. }
  66. void have(int x, int y){
  67. int len1 = engineer[x].size();
  68. int len2 = project[y].size();
  69. for(int i = 0; i < len2; ++i){
  70. bool ok = false;
  71. for(int j = 0; j < len1; ++j){
  72. if(engineer[x][j] == project[y][i]){
  73. ok = true;
  74. break;
  75. }
  76. }
  77. if(ok) work[x][y] |= (1 << i);
  78. }
  79. }
  80. int main(){
  81. int T;
  82. scanf("%d", &T);
  83. int kase = 0;
  84. while(T--){
  85. mp.clear();
  86. ans = 0;
  87. for(int i = 0; i < MAXN; ++i){
  88. project[i].clear();
  89. engineer[i].clear();
  90. t[i].clear();
  91. }
  92. memset(work, 0, sizeof work);
  93. memset(status, 0, sizeof status);
  94. scanf("%d%d", &n, &m);
  95. int k, x;
  96. for(int i = 1; i <= n; ++i){
  97. scanf("%d", &k);
  98. for(int j = 0; j < k; ++j){
  99. scanf("%d", &x);
  100. t[i].push_back(x);
  101. }
  102. }
  103. for(int i = 1; i <= m; ++i){
  104. scanf("%d", &k);
  105. for(int j = 0; j < k; ++j){
  106. scanf("%d", &x);
  107. mp[x] = 1;
  108. engineer[i].push_back(x);
  109. }
  110. }
  111. projectnum = 0;
  112. for(int i = 1; i <= n; ++i){
  113. int l = t[i].size();
  114. bool ok = true;
  115. for(int j = 0; j < l; ++j){
  116. if(!mp.count(t[i][j])){
  117. ok = false;
  118. break;
  119. }
  120. }
  121. if(ok) project[++projectnum] = t[i];
  122. }
  123. for(int i = 1; i <= m; ++i){
  124. for(int j = 1; j <= projectnum; ++j){
  125. have(i, j);
  126. }
  127. }
  128. dfs(1, 0);
  129. printf("Case #%d: %d\n", ++kase, ans);
  130. }
  131. return 0;
  132. }

  

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. JSONObject遍历并替换部分json值

    今天做接口对接,在更新价格时,最开始传的值为整数,发现报错,询问对方后得知需要统一保留两位小数,没有则为.00,于是对原有JSONObject进行改造,遍历并替换其中的值.下面贴出代码: JSONOb ...

  2. Android Studio中 no module 问题,解决方法

    等它执行完以后就好了 或者根据提示手动下载缺失的.

  3. 一文解读CAP (转)

    分布式系统(distributed system)正变得越来越重要,大型网站几乎都是分布式的. 分布式系统的最大难点,就是各个节点的状态如何同步.CAP 定理是这方面的基本定理,也是理解分布式系统的起 ...

  4. 更换JAVA程序的界面风格

    /*这个程序主要更换JAVA的界面风格的 * 后两个Mac,CTK风格要在相关的操作系统上才能实现 */import java.awt.*;import javax.swing.*;import ja ...

  5. Js为Dom元素绑定事件须知

    为异步加载的Dom 元素绑定事件必须在加载完成之后绑定: $('body').load('LearnClickBinding.ashx');$('a').click(function () { ale ...

  6. Spring注解@ConfigurationPropertie

    @ConfigurationPropertie作用 参考的博客 springboot中@ConfigurationProperties注解的工作原理 @ConfigurationProperties是 ...

  7. TP-Link TL-WR841N v14 CVE-2019-17147 缓冲区溢出漏洞分析笔记v2018.12.31

    0x00 背景 Httpd服务中的缓冲区溢出漏洞 复现参考文章https://www.4hou.com/posts/gQG9 Binwalk -Me 解压缩 File ./bin/busybox文件类 ...

  8. logj4.xml

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration PU ...

  9. computed、methods、watch

    computed:计算属性将被混入到 Vue 实例中.所有 getter 和 setter 的 this 上下文自动地绑定为 Vue 实例. methods:methods 将被混入到 Vue 实例中 ...

  10. Celery的常用知识

    什么是Clelery   Celery是一个简单.灵活且可靠的,处理大量消息的分布式系统.专注于实时处理的异步任务队列.同时也支持任务调度. Celery的架构由三部分组成,消息中间件(message ...