hdu 6006 Engineer Assignment(状压DP)
来源:互联网 发布:php程序员是什么意思 编辑:程序博客网 时间:2024/06/14 06:57
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 theith 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.
There are N projects owned by a director. For the
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 integerCi 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 ith engineer.
with an integer
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.
∙1≤T≤100.
∙1≤N,M≤10.
∙1≤Ci≤3.
∙1≤Di≤2.
∙1≤ai,j,bi,j≤100.
limits
Sample Input
13 43 40 77 643 10 40 203 40 20 772 40 772 77 642 40 102 20 77
Sample Output
Case #1: 2HintFor 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[N];int dp[20][1<<15], a[20][30], b[20][30];void init(){ memset(dp,0,sizeof(dp)); return ;}vector<int>p[N];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;}
阅读全文
0 0
- hdu 6006 Engineer Assignment(状压dp)
- hdu 6006 Engineer Assignment(状压DP)
- hdu 6006 Engineer Assignment
- HDU-6006-Engineer Assignment
- hdu 6006 Engineer Assignment(状压)
- HDU6006 Engineer Assignment 状压DP
- HDU 6006 Engineer Assignment (状态压缩DP)
- HDU 6006 Engineer Assignment(状态压缩dp)
- Engineer Assignment dp
- Codeforces 101206 H & HDU 6006 Engineer Assignment
- Engineer Assignment HDU
- Engineer Assignment HDU
- HDU6006-Engineer Assignment
- 【HOJ2662】Pieces Assignment(状压dp)
- Assignment HDU
- HDU 6006 状压DP
- HDU 2853 Assignment KM
- hdu 5289 Assignment
- poj 3468 线段树
- poj1094 Sorting It All Out
- js中for循环的作用域;函数调用的理解;数组对象的理解;
- 输出乘法顺序表
- 求C_18^13的值
- hdu 6006 Engineer Assignment(状压DP)
- spring注解
- docker本机启动多台容器导致出现后续容器启动失败
- 留言板功能
- python 修饰器
- 没有对象的指针是野指针【用C语言做生日贺卡】
- 智能指针
- 图像处理之使用人机交互截取图片
- SIMPLE authentication is not enabled. Available:[TOKEN, KERBEROS]