hdu 6006 Engineer Assignment 状压dp
Engineer Assignment
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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.
3 4
3 40 77 64
3 10 40 20
3 40 20 77
2 40 77
2 77 64
2 40 10
2 20 77
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个地点,每个地点有多个种类问题,M个工程师,一个工程可以解决一些问题;求最多解决几个;
思路:状态压缩dp;
dp[i][j]表示解决前i个,用状态压缩的使用了j的工程师,最多解决问题数;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<bitset>
#include<time.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-8
#define bug(x) cout<<"bug"<<x<<endl;
const int N=+,M=1e6+,inf=1e9+,MOD=1e9+;
const LL INF=1e18+,mod=1e9+; struct Hash
{
int flag[],tot;
void init()
{
memset(flag,,sizeof(flag));
tot=;
}
int operator [](int x)
{
if(flag[x])return flag[x];
flag[x]=++tot;
return flag[x];
}
}f;
LL a[N],b[N];
int dp[N][];
int check(int pos,int x,int y,int m)
{
LL ans=;
for(int i=;i<=m;i++)
{
LL xx=(1LL<<(i-))&x;
LL zz=(1LL<<(i-))&y;
if(xx^zz)
{
ans|=b[i];
}
}
if((ans|a[pos])==ans)return ;
return ;
}
int main()
{
int T,cas=;
scanf("%d",&T);
while(T--)
{
f.init();
memset(a,,sizeof(a));
memset(b,,sizeof(b));
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
int t;
scanf("%d",&t);
while(t--)
{
int x;
scanf("%d",&x);
a[i]|=(1LL<<(f[x]-));
}
}
for(int i=;i<=m;i++)
{
int t;
scanf("%d",&t);
while(t--)
{
int x;
scanf("%d",&x);
b[i]|=(1LL<<(f[x]-));
}
}
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
{
for(int j=;j<=(<<m)-;j++)
{
for(int k=;k<=j;k++)
{
if((k|j)!=j)continue;
dp[i][j]=max(dp[i][j],dp[i-][k]+check(i,j,k,m));
}
}
}
printf("Case #%d: %d\n",cas++,dp[n][(<<m)-]);
}
return ;
}
hdu 6006 Engineer Assignment 状压dp的更多相关文章
- HDU - 6006 Engineer Assignment (状压dfs)
题意:n个工作,m个人完成,每个工作有ci个阶段,一个人只能选择一种工作完成,可以不选,且只能完成该工作中与自身标号相同的工作阶段,问最多能完成几种工作. 分析: 1.如果一个工作中的某个工作阶段没有 ...
- 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 ...
- HDU 5765 Bonds(状压DP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5765 [题目大意] 给出一张图,求每条边在所有边割集中出现的次数. [题解] 利用状压DP,计算不 ...
- hdu 3681(bfs+二分+状压dp判断)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 思路:机器人从出发点出发要求走过所有的Y,因为点很少,所以就能想到经典的TSP问题.首先bfs预 ...
- hdu 4778 Gems Fight! 状压dp
转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...
- hdu 4856 Tunnels (bfs + 状压dp)
题目链接 The input contains mutiple testcases. Please process till EOF.For each testcase, the first line ...
- HDU 4272 LianLianKan (状压DP+DFS)题解
思路: 用状压DP+DFS遍历查找是否可行.假设一个数为x,那么他最远可以消去的点为x+9,因为x+1~x+4都能被他前面的点消去,所以我们将2进制的范围设为2^10,用0表示已经消去,1表示没有消去 ...
随机推荐
- Centos7 HyperLedger Fabric 1.4 生产环境部署
Kafka生产环境部署案例采用三个排序(orderer)服务.四个kafka.三个zookeeper和四个节点(peer)组成,共准备八台服务器,每台服务器对应的服务如下所示: kafka案例网络拓扑 ...
- Tomcat配置技巧
1. 配置系统管理(Admin Web Application) 大多数商业化的J2EE服务器都提供一个功能强大的管理界面,且大都采用易于理解的Web应用界面.Tomcat按照自己的方式,同样提供一个 ...
- LeetCode 15 输入无序、有重复,输出排重版 3-Sum
V1 粗暴的遍历,时间复杂度O(N³) func threeSumClosest(nums []int, target int) int { min := 0 result := 0 for i := ...
- Elasticsearch.安装插件(head)
Elasticsearch.安装插件(head) 环境: Linux 7.x jdk1.8 目录结构(跟目录多了两个文件) /resources ### 存放软件源 /u01/ ...
- windows 下安装weblogic
下载weblogic安装文件 https://www.oracle.com/technetwork/middleware/weblogic/downloads/index.html 在目录下, 下载后 ...
- Android -- 《 最美有物》好看的点赞效果
1,前天在鸿洋的公众号上看到一款不错的点赞效果,是仿最美有物的点赞,再加上自己最近学习状态很差,自己想着通过这个效果练手一下,果然,花了整整两天的时间,按照以前的效率的话一天就够了,哎,已经调整了一个 ...
- PyCharm:no module named * 解决方法
1.成功安装模块,无法导入 今天安装完模块pyppeteer,pycharm导入失败,从python的Lib下可以清楚的看到已经安装成功 2.添加当前python环境,不使用默认项目的环境 file& ...
- day16 python之匿名函数,递归函数
匿名函数 匿名函数格式 函数名 = lambda 参数 :返回值 #参数可以有多个,用逗号隔开 #匿名函数不管逻辑多复杂,只能写一行,且逻辑执行结束后的内容就是返回值 #返回值和正常的函数一样可以是任 ...
- Requests卡死问题
https://www.cnblogs.com/niansi/p/7143736.html https://blog.csdn.net/pilipala6868/article/details/807 ...
- you've successfully authenticated, but Gitee.com does not provide she access.
如果都是正常的生成ssh的操作,还是会报这个错误,那么就是.... 你没更改文件夹的权限,这个坑跳了很久(汗...) sudo chmod 777 -r 文件夹