HDU 6006 状压dp
Engineer Assignment
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 849 Accepted Submission(s): 301
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.
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.
limits
∙1≤T≤100.
∙1≤N,M≤10.
∙1≤Ci≤3.
∙1≤Di≤2.
∙1≤ai,j,bi,j≤100.
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.
题意:
有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的更多相关文章
- Engineer Assignment HDU - 6006 状压dp
http://acm.split.hdu.edu.cn/showproblem.php?pid=6006 比赛的时候写了一个暴力,存暴力,过了,还46ms 那个暴力的思路是,预处理can[i][j]表 ...
- HDU 4778 状压DP
一看就是状压,由于是类似博弈的游戏.游戏里的两人都是绝对聪明,那么先手的选择是能够确定最终局面的. 实际上是枚举最终局面情况,0代表是被Bob拿走的,1为Alice拿走的,当时Alice拿走且满足变换 ...
- HDU 3001 状压DP
有道状压题用了搜索被队友骂还能不能好好训练了,, hdu 3001 经典的状压dp 大概题意..有n个城市 m个道路 成了一个有向图.n<=10: 然后这个人想去旅行.有个超人开始可以把他扔到 ...
- hdu 2809(状压dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2809 思路:简单的状压dp,看代码会更明白. #include<iostream> #in ...
- hdu 2167(状压dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2167 思路:经典的状压dp题,前后,上下,对角8个位置不能取,状态压缩枚举即可所有情况,递推关系是为d ...
- hdu 3254 (状压DP) Corn Fields
poj 3254 n乘m的矩阵,1表示这块区域可以放牛,0,表示不能,而且不能在相邻的(包括上下相邻)两个区域放牛,问有多少种放牛的方法,全部不放也是一种方法. 对于每块可以放牛的区域,有放或者不放两 ...
- HDU 5823 (状压dp)
Problem color II 题目大意 定义一个无向图的价值为给每个节点染色使得每条边连接的两个节点颜色不同的最少颜色数. 对于给定的一张由n个点组成的无向图,求该图的2^n-1张非空子图的价值. ...
- hdu 4739 状压DP
这里有状态压缩DP的好博文 题目:题目比较神,自己看题目吧 分析: 大概有两种思路: 1.dfs,判断正方形的话可以通过枚举对角线,大概每次减少4个三角形,加上一些小剪枝的话可以过. 2.状压DP,先 ...
- Travel(HDU 4284状压dp)
题意:给n个城市m条路的网图,pp在城市1有一定的钱,想游览这n个城市(包括1),到达一个城市要一定的花费,可以在城市工作赚钱,但前提有工作证(得到有一定的花费),没工作证不能在该城市工作,但可以走, ...
随机推荐
- Scrum Meeting 3 -2014.11.5
这几天小伙伴们都在努力,研究出不少改进方案并加以设计和实施了,分词算法的优化进度可观,而其他的任务在改进的过程中产生了些问题,对于之前代码的设计感到疑惑,我们找到了上届的学长们咨询,他们也给出了不少建 ...
- 团队作业 & alpha最终测试报告
本次ALPHA版本测试是依据Daily Scrum11.16(http://www.cnblogs.com/newbe/p/4101339.html)分配的任务有序进行的,从11.16~11.23.为 ...
- No.1000_第五次团队会议
光辉的一夜 今夜注定是不平凡的一夜.是崔强同学伟大的一夜. 昨天因为实验室项目,我刚上完编译课就被学院叫走去做项目,当时我就很无奈,因为说好了要和崔强一起实现下午的前端,他写界面我写底层逻辑,这样我们 ...
- 20172329 2018-2019-2 《Java软件结构与数据结构》实验二报告
20172329 2018-2019-2 <Java软件结构与数据结构>实验二报告 课程:<Java软件结构与数据结构> 班级: 1723 姓名: 王文彬 学号:2017232 ...
- 20162328蔡文琛 week05 大二
20162328 2017-2018-1 <程序设计与数据结构>第5周学习总结 教材学习内容总结 集合是收集元素并组织其他对象的对象. 集合中的元素一般由加入集合的次序或元素之间的某些固有 ...
- web10 动态action的应用
电影网站:www.aikan66.com 项目网站:www.aikan66.com游戏网站:www.aikan66.com图片网站:www.aikan66.com书籍网站:www.aikan66.co ...
- 软工1816 · 作业(十二)Beta答辩总结
组长博客 宣传视频 github团队项目仓库 本组成员 队员姓名与学号 124 王彬(组长) 206 赵畅 215 胡展瑞 320 李恒达 131 佘岳昕 431 王源 206 陈文垚 209 陈志炜 ...
- 动态生成CheckBox(Winform程序)
在做用户权限设置功能时,需要做一个动态生成权限列表的功能.(笔记.分享) //1.清空权限控件组的默认控件 panelPermissions.Controls.Clear(); _groupBoxLi ...
- sql中Union和union all的使用
该文转载自:http://www.cnblogs.com/chaobaojun/archive/2009/12/24/1631508.html 在MS-SQL如果将两个或更多查询的结果组合为单个结果集 ...
- 个人阅读&个人总结
个人阅读作业+总结 助教推荐的那些文章都是软件工程上的经典文章,阅读后感受到软件工程本身的深度,之前学习的软件工程都只是皮毛之中的皮毛而已.随着软件规模的越来越庞大,软件工程已经成为了软件开发中的必备 ...