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),到达一个城市要一定的花费,可以在城市工作赚钱,但前提有工作证(得到有一定的花费),没工作证不能在该城市工作,但可以走, ...
随机推荐
- 常用函数-filter、map、reduce、sorted
常用函数 filter map reduce sorted和列表自带sort 待续... 一.filter函数 1.说明 filter()函数接收一个函数 f 和一个可迭代对象,这个函数 f 的作用是 ...
- scrapy有用的(代理,user-agent,随机延迟等)
代理 方法一(待测试) 见scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware import os # 设置相应的代理用户名密码,主机和 ...
- 第7讲:SQL Server简介
SQL Server是微软公司提供的一款关系数据库管理系统. 操作数据库有两种方式:SQL语句和可视化的SSMS,该文章所有操作均基于SSMS. 一.SSMS(SQL Server Managemen ...
- 20172319 《Java程序设计教程》 第9周学习总结
20172319 2018.05.06-05.14 <Java程序设计教程>第9周学习总结 目录 教材学习内容总结 教材学习中的问题和解决过程 代码调试中的问题和解决过程 代码托管 上周考 ...
- MySQL课堂练习 20162315
练习内容 1.参考教材相关代码,提交能连接到world的截图(有学号水印) 2.查询world数据库,获得人口超过500万的所有城市的列表. 3.查询world数据库,获得New Jersey州所有城 ...
- JVM面试问题
JVM主要包括:程序计数器(Program Counter),Java堆(Heap),Java虚拟机栈(Stack),本地方法栈(Native Stack),方法区(Method Area) 1.程序 ...
- nginx配置hls
备注:本来是想用浏览器播放hls,后来没有成功,最后使用flash播放rtmp的方案.所以下面的配置未使用. 修改/usr/local/nginx/conf/nginx.conf文件内容如下: wor ...
- 蜗牛慢慢爬 LeetCode 36.Valid Sudoku [Difficulty: Medium]
题目 Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could ...
- Beta阶段DAY2
一.提供当天站立式会议照片一张 二.每个人的工作 1.讨论项目每个成员的昨天进展 刘阳航:删除多余按钮,调整界面. 林庭亦:删除麻烦的颜色设置. 郑子熙:添加新增按钮. 陈文俊:重新规划面板及功能. ...
- ORACLE LOG的管理
CREATE OR REPLACE PACKAGE PLOG IS /** * package name : PLOG *<br/> *<br/> *See : <a h ...