hdu 6006 Engineer Assignment(状压DP)
2017-09-26 19:12
375 查看
Engineer Assignment
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 456 Accepted Submission(s): 149
Problem Description
In Google, there are many experts of different areas. For example, MapReduce experts, Bigtable experts, SQL experts, etc. Directors need to properly assign experts to various projects in order to make the projects going smoothly.
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.
Input
The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with a line consisting of 2 integers, N the number of projects and M the number of engineers. Then N lines follow. The ith line
containing the information of the ith project
starts
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 ithline
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 ith engineer.
Output
For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the maximum number of projects can be successfully finished.
limits
∙1≤T≤100.∙1≤N,M≤10.
∙1≤Ci≤3.
∙1≤Di≤2.
∙1≤ai,j,bi,j≤100.
Sample Input
1
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
Sample Output
Case #1: 2
Hint
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个工程师,每个工程师会一些领域,问这些工程师最多完成多少任务
题解:先预处理出能第i个任务可以由哪些人一起完成,因为人数不多,所以可以用状态压缩,然后dp[i][j]来表示表前i个任务,状态为j时,最多完成的任务数
一开始用一维表状态一直wa 改成二维 第一维是前i个工程的最大能完成数目的最优状态 当考虑第i+1个时 可能选或者不选
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
#include <bits/stdc++.h>
using namespace std;
const int N = 120;
typedef long long LL;
int vis
;
int dp[20][1<<15], a[20][30], b[20][30];
void init()
{
memset(dp,0,sizeof(dp));
return ;
}
vector<int>p
;
int main()
{
//cout<<(1<<30)<<endl;
int t, ncase=1;
scanf("%d", &t);
while(t--)
{
int n,m;
scanf("%d %d", &n, &m);
for(int i=0; i<=n; i++) p[i].clear();
init();
int x, y;
for(int i=1; i<=n; i++)
{
scanf("%d", &x);
a[i][0]=x;
for(int j=1; j<=x; j++) scanf("%d", &a[i][j]);
}
for(int i=0; i<m; i++)
{
scanf("%d", &x);
b[i][0]=x;
for(int j=1; j<=x; j++) scanf("%d", &b[i][j]);
}
for(int j=1; j<=n; j++)
{
for(int i=0; i<(1<<m); i++)
{
memset(vis,0,sizeof(vis));
int cnt=0;
for(int j=0; j<m; j++)
{
if(i&(1<<j))
{
cnt++;
for(int k=1; k<=b[j][0]; k++)
{
vis[b[j][k]]=1;
}
}
}
int flag=0;
for(int k=1; k<=a[j][0]; k++)
{
if(!vis[a[j][k]])
{
flag=1;
break;
}
}
if(flag==0) p[j].push_back(i);
}
}
int ans=0;
for(int i=1; i<=n; i++)
{
for(int j=0; j<(1<<m); j++)
{
for(int k=0; k<p[i].size(); k++)
{
if((j|p[i][k])==j)dp[i][j]=max(dp[i][j],dp[i-1][j-p[i][k]]+1);
}
dp[i][j]=max(dp[i][j],dp[i-1][j]);
ans=max(ans,dp[i][j]);
}
}
printf("Case #%d: %d\n",ncase++, ans);
}
return 0;
}
相关文章推荐
- HDU - 6006 (状压dp)
- hdu 6006 Engineer Assignment(状压dp)
- Engineer Assignment HDU - 6006(状压dp)
- HDU 6006 Engineer Assignment (状压DP)
- HDU 6006 状压DP
- 【HDU 6006】Engineer Assignment(状压DP)
- HDU 1074 Doing Homework(状压DP)
- hdu 5823(状压DP)
- hdu 4336 概率DP 状压DP
- hdu 1074 Doing Homework (状压dp)
- hdu 1074 Doing Homework(状压DP)
- HDU 1992 Tiling a Grid With Dominoes (状压 dp)
- 【DP】 HDU 4539 郑厂长系列故事——排兵布阵 状压
- hdu1074 Doing Homework(状压dp)
- 【DP】 HDU 3182 Hamburger Magi 状压
- HDU 3001 Travelling 状压DP
- HDU - 4568 最短路 + 状压dp
- HDU 6006 Engineer Assignment (状态压缩DP)
- HDU 3182 Hamburger Magi(状压dp)
- hdu 1074 Doing Homework(状压DP)