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),到达一个城市要一定的花费,可以在城市工作赚钱,但前提有工作证(得到有一定的花费),没工作证不能在该城市工作,但可以走, ...
随机推荐
- Nginx 配置优化
一.开启Gzip 1.参数 gzip on;gzip_min_length 1k;gzip_buffers 4 16k;gzip_comp_level 2;gzip_types text/plain ...
- 作业要求 20181127-5 Beta发布用户使用报告
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2450 一.用户反馈 反馈截图(部分) 三.用户反馈情况统计图
- spring boot的maven项目报404错误
$.ajax({ async: false, type: "POST", url:'searchFileSource', contentType : "applicati ...
- 软工1816 · Beta冲刺(1/7)
团队信息 队名:爸爸饿了 组长博客:here 作业博客:here 组员情况 组员1(组长):王彬 过去两天完成了哪些任务 完成beta冲刺阶段的任务安排 整理博客 接下来的计划 & 还剩下哪些 ...
- slf4j+log4j的初次使用
关于这两者的组合应用带来的好处,google都有 就不说了. 首先说下配置, 工作笔记:在myeclipse 中创建一个java project 创建一个 TestSlf4J 类 package co ...
- 关于JoptionPane提示框
import java.util.*; import javax.swing.JOptionPane; import javax.swing.UIManager; public class Main ...
- POJ 1239 Increasing Sequences 动态规划
题目链接: http://poj.org/problem?id=1239 Increasing Sequences Time Limit: 1000MSMemory Limit: 10000K 问题描 ...
- 第一个spring冲刺第二天
讨论成员:王俊凯.罗凯杰.王逸辉.马志磊 地点:宿舍 话题:讨论关于安卓的控件的应用和如何调用 选题:四则运算 方向:更加实用的计算器功能,功能更加实用并且简单,没有太多的繁琐操作,可以的话会加上些趣 ...
- 18_集合框架_第18天_集合、Iterator迭代器、增强for循环 、泛型_讲义
今日内容介绍 1.集合 2.Iterator迭代器 3.增强for循环 4.泛型 01集合使用的回顾 *A:集合使用的回顾 *a.ArrayList集合存储5个int类型元素 public stati ...
- 解决getOutputStream() has alerady been called for this response
在用tomcat启动一个web项目(SpringBoot)的时候报错: getOutputStream() has alerady been called for this response 但是如果 ...