HDU - 6006 Engineer Assignment

我参考了这份题解.

贴上我比较拙的代码,留念一下。

/**
* 想到状态压缩的dp问题就解决了一半。
*/ #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <set> using namespace std;
typedef long long int LL; const int maxn=1e6+10;
vector<int> status[20];//存储每个项目对赢工程师的分配状态;
int project[15][5],engineer[15][5];//接收输入数据
bool have[105];//用来判断某些工程师的组合能否完成某一个项目
int dp[15][1029];//dp[i][s]前i个项目分配状态为s最对完成多少个项目;
//那么转移方程 dp[i][s]=max(dp[i-1][s-status]+1,dp[i-1][s]);
int n,m; bool judge(int p,int status) //判断该选择工程师的状态能否完成第p个项目;
{
memset(have,0,sizeof(have));
for(int i=0;i<m;i++)
{
if(status&(1<<i))
{
for(int k=1;k<=engineer[i+1][0];k++)
have[engineer[i+1][k]]=1;
}
}
for(int i=1;i<=project[p][0];i++)
if(have[project[p][i]]==0) return false;
return true;
}
int main()
{
int ncase,cas=1;
scanf("%d",&ncase);
while(ncase--)
{
printf("Case #%d: ",cas++);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
status[i].clear();
scanf("%d",&project[i][0]);
for(int j=1;j<=project[i][0];j++) scanf("%d",&project[i][j]);
}
for(int i=1;i<=m;i++)
{
scanf("%d",&engineer[i][0]);
for(int j=1;j<=engineer[i][0];j++) scanf("%d",&engineer[i][j]);
}
for(int i=1;i<=n;i++)
for(int s=0;s<(1<<m);s++)
if(judge(i,s)) status[i].push_back(s);
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
{
for(int s=0;s<(1<<m);s++)
{
for(int j=0;j<(int)status[i].size();j++)
{
if((s|status[i][j])==s)
{
dp[i][s]=max(dp[i][s],dp[i-1][s-status[i][j]]+1);
}
}
dp[i][s]=max(dp[i][s],dp[i-1][s]);
//printf("dp[%d][%d]=%d\n",i,s,dp[i][s]);
}
}
int cnt=(1<<m)-1;
printf("%d\n",dp[n][cnt]);
}
return 0;
} /*
1
10 10
3 25 10 10
3 20 20 20
3 25 10 10
3 20 20 20
3 25 10 10
3 20 20 20
3 25 10 10
3 20 20 20
3 25 10 10
3 20 20 20
2 20 10
2 20 10
2 20 10
2 20 10
2 20 10
2 20 10
2 20 10
2 20 10
2 20 10
2 20 10 */

hdu 6006的更多相关文章

  1. HDU 6006 Engineer Assignment:状压dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6006 题意: 在Google中,有个n项目,m个专家.第i个项目涉及c[i]个领域,分别为a[i][0 ...

  2. Engineer Assignment HDU - 6006 状压dp

    http://acm.split.hdu.edu.cn/showproblem.php?pid=6006 比赛的时候写了一个暴力,存暴力,过了,还46ms 那个暴力的思路是,预处理can[i][j]表 ...

  3. hdu 6006 Engineer Assignment 状压dp

    Engineer Assignment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  4. HDU 6006 状压dp

    Engineer Assignment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  5. 【HDU 6006】Engineer Assignment(状压DP)

    Problem Description In Google, there are many experts of different areas. For example, MapReduce exp ...

  6. HDU - 6006 Engineer Assignment (状压dfs)

    题意:n个工作,m个人完成,每个工作有ci个阶段,一个人只能选择一种工作完成,可以不选,且只能完成该工作中与自身标号相同的工作阶段,问最多能完成几种工作. 分析: 1.如果一个工作中的某个工作阶段没有 ...

  7. CCPC 2016-2017, Finals

    A. HDU 5999 The Third Cup is Free 简单模拟. B. HDU 6000 Wash n 件衣服, m 个洗衣机,k 个烘干机.每个洗衣机和烘干机需要不同的时间.问 n 件 ...

  8. ZROI week1

    \[ZROI day1\] \[Grid\] 题目描述 给定一个矩阵,小写字母,求一条路径使得从\((1,1) -> (n,m)\),字典序最小,并且每次只能向右或者向下. 题解 先考虑如果没有 ...

  9. hdu 2199 Can you solve this equation?(高精度二分)

    http://acm.hdu.edu.cn/howproblem.php?pid=2199 Can you solve this equation? Time Limit: 2000/1000 MS ...

随机推荐

  1. VueJS字符串反转:String.reverse()

    HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <titl ...

  2. java 设计模式 -- 责任链模式

    设计模式 – 责任链模式 介绍: 责任链模式是一种动态行为模式,有多个对象,每一个对象分别拥有其下家的引用.连起来形成一条链.待处理对象则传到此链上,在此链进行传递,且待处理对象并不知道此会被链上的哪 ...

  3. 用递归法将一个整数n转换成字符串。

    用递归法将一个整数n转换成字符串. 比如,输入483,应输出字符串"483".n的位数不确定,能够是随意位数的整数. #include "stdafx.h" # ...

  4. Character set &#39;utf8mb4&#39; is not a compiled character set

    近期在一次MySQL数据迁移的过程中遭遇了字符集的问题,提示为"Character set 'utf8mb4' is not a compiled character set".即 ...

  5. Java 线程第三版 第五章 极简同步技巧 读书笔记

    一.能避免同步吗? 取得锁会由于下面原因导致成本非常高:     取得由竞争的锁须要在虚拟机的层面上执行很多其它的程序代码.     要取得有竞争锁的线程总是必须等到锁被释放后. 1. 寄存器的效应 ...

  6. modelsim-altera IP核仿真

    modelsim 仿真fifo时出现 Instantiation of 'scfifo' failed. The design unit was not found. 2012-07-21 13:27 ...

  7. Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml, reason: Connect

    Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml, reason: Connect ...

  8. hashmap和ConcurrentHashMap

    hashmap市基于table和单向链表 table中存放hash值,table中存放着单向链表,查询时先计算对象hash值,找到table中对应值,然后查询链表. ConcurrentHashMap ...

  9. iOS打包(ipa包)

    1.打开XCode打开project文件.选择Product,再点击Archive. 2.鼠标右键点击Shoe In Finder 3.鼠标右键选择"显示包内容" 4.鼠标左键双击 ...

  10. 两个DataGridEHToExcel

    procedure TForm1.N1Click(Sender: TObject); var    GridtoExcel: TDBGridEhToExcel; begin    try    Gri ...