HDU - 6006 Engineer Assignment (状压dfs)
题意: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)的更多相关文章
- hdu 6006 Engineer Assignment 状压dp
Engineer Assignment Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU 6006 Engineer Assignment:状压dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6006 题意: 在Google中,有个n项目,m个专家.第i个项目涉及c[i]个领域,分别为a[i][0 ...
- HDU6006:Engineer Assignment(状压DP)
传送门 题意 给出n个工程,m个工程师,每个工程和工程师需要/拥有若干个技能,询问能够完成的最大工程个数,每个工程师用一次 分析 dp[i][j]表示前i个工程用的工程师集合为j的最大工程个数,那么有 ...
- hdu 3247 AC自动+状压dp+bfs处理
Resource Archiver Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 100000/100000 K (Java/Ot ...
- hdu 2825 aC自动机+状压dp
Wireless Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- ZOJ 1609 Equivalence(状压+dfs减枝)
ZOJ Problem Set - 1609 Equivalence Time Limit: 5 Seconds Memory Limit: 32768 KB When learning m ...
- bzoj1725: [Usaco2006 Nov]Corn Fields牧场的安排(状压dfs)
1725: [Usaco2006 Nov]Corn Fields牧场的安排 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1122 Solved: 80 ...
- 状压dfs小记
一点前(tu)言(cao) 真的考起dfs来可谓是什么都能往dfs上套 状压不止能dp,还能与dfs结合成为搜索好(duliu)题 剪枝卡常司空见惯(打开题解一看并不是纯dfs,emmmm) 开始正文 ...
- HDU 4272 LianLianKan (状压DP+DFS)题解
思路: 用状压DP+DFS遍历查找是否可行.假设一个数为x,那么他最远可以消去的点为x+9,因为x+1~x+4都能被他前面的点消去,所以我们将2进制的范围设为2^10,用0表示已经消去,1表示没有消去 ...
随机推荐
- JSONObject遍历并替换部分json值
今天做接口对接,在更新价格时,最开始传的值为整数,发现报错,询问对方后得知需要统一保留两位小数,没有则为.00,于是对原有JSONObject进行改造,遍历并替换其中的值.下面贴出代码: JSONOb ...
- Android Studio中 no module 问题,解决方法
等它执行完以后就好了 或者根据提示手动下载缺失的.
- 一文解读CAP (转)
分布式系统(distributed system)正变得越来越重要,大型网站几乎都是分布式的. 分布式系统的最大难点,就是各个节点的状态如何同步.CAP 定理是这方面的基本定理,也是理解分布式系统的起 ...
- 更换JAVA程序的界面风格
/*这个程序主要更换JAVA的界面风格的 * 后两个Mac,CTK风格要在相关的操作系统上才能实现 */import java.awt.*;import javax.swing.*;import ja ...
- Js为Dom元素绑定事件须知
为异步加载的Dom 元素绑定事件必须在加载完成之后绑定: $('body').load('LearnClickBinding.ashx');$('a').click(function () { ale ...
- Spring注解@ConfigurationPropertie
@ConfigurationPropertie作用 参考的博客 springboot中@ConfigurationProperties注解的工作原理 @ConfigurationProperties是 ...
- TP-Link TL-WR841N v14 CVE-2019-17147 缓冲区溢出漏洞分析笔记v2018.12.31
0x00 背景 Httpd服务中的缓冲区溢出漏洞 复现参考文章https://www.4hou.com/posts/gQG9 Binwalk -Me 解压缩 File ./bin/busybox文件类 ...
- logj4.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration PU ...
- computed、methods、watch
computed:计算属性将被混入到 Vue 实例中.所有 getter 和 setter 的 this 上下文自动地绑定为 Vue 实例. methods:methods 将被混入到 Vue 实例中 ...
- Celery的常用知识
什么是Clelery Celery是一个简单.灵活且可靠的,处理大量消息的分布式系统.专注于实时处理的异步任务队列.同时也支持任务调度. Celery的架构由三部分组成,消息中间件(message ...