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),到达一个城市要一定的花费,可以在城市工作赚钱,但前提有工作证(得到有一定的花费),没工作证不能在该城市工作,但可以走, ...
随机推荐
- oracle安装出错/runInstaller
http://blog.csdn.net/yabingshi_tech/article/details/48313955 http://www.cnblogs.com/lihaozy/archive/ ...
- Shell重新学习(忘光了)
成功和失败都放同一个文件 调试shell
- 使用谷歌浏览器调试WEB前端的一些必备调试技巧
转载:http://www.techug.com/post/chrome-debug-tips.html Chrome的开发者工具是个很强大的东西,相信程序员们都不会陌生,不过有些小功能可能并不为大众 ...
- 20162328蔡文琛 大二 十二周课上测试 hash
- YQCB冲刺周第六天
站立会议如上图 任务看板: 今天的任务为依旧为将用户记录的数据添加到数据库中,以及金额球的设置. 遇到的问题为金额球在jsp页面的显示.
- Sprint2
进展:主要进行了在安卓手机端进行APP开发的资料及有关学习的视频的查找等.了解也学习了这些资料还有技术.第一个任务完成了一半. 燃尽图:
- Task 6.2冲刺会议六 /2015-5-19
今天主要写的是登陆界面,用户状态,历史登录信息,默认用户等等.由于大部分时间都是把代码组合拳起来的过程,所以总会出现各种bug,有好大一部分不会修复.明天要继续这一部分还有熟悉一下聊天的主界面.
- 《[C#] int与System.Int32有什么区别》
最近园里的TeamOne写了一篇<[C#] int与System.Int32有什么区别>,发现里面有不少精彩的评论,所以忍不住想这篇文章总结一下:> 本文的主要参考资料: 1.< ...
- Eclipse下使用Git
安装Git 有的eclipse已经自带了Git了,就不用安装了. 如果,想重新安装,可以先卸载git,卸载 不同eclipse卸载不一样: 1.在Eclipse中依次点击菜单"Help&qu ...
- UIPickerView的使用
简介:UIPickerView是一个选择器控件,它比UIDatePicker更加通用,它可以生成单列的选择器,也可生成多列的选择器,而且开发者完全可以自定义选择项的外观,因此用法非常灵活.UIPick ...