hdu 6006
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的更多相关文章
- HDU 6006 Engineer Assignment:状压dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6006 题意: 在Google中,有个n项目,m个专家.第i个项目涉及c[i]个领域,分别为a[i][0 ...
- Engineer Assignment HDU - 6006 状压dp
http://acm.split.hdu.edu.cn/showproblem.php?pid=6006 比赛的时候写了一个暴力,存暴力,过了,还46ms 那个暴力的思路是,预处理can[i][j]表 ...
- hdu 6006 Engineer Assignment 状压dp
Engineer Assignment Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU 6006 状压dp
Engineer Assignment Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- 【HDU 6006】Engineer Assignment(状压DP)
Problem Description In Google, there are many experts of different areas. For example, MapReduce exp ...
- HDU - 6006 Engineer Assignment (状压dfs)
题意:n个工作,m个人完成,每个工作有ci个阶段,一个人只能选择一种工作完成,可以不选,且只能完成该工作中与自身标号相同的工作阶段,问最多能完成几种工作. 分析: 1.如果一个工作中的某个工作阶段没有 ...
- CCPC 2016-2017, Finals
A. HDU 5999 The Third Cup is Free 简单模拟. B. HDU 6000 Wash n 件衣服, m 个洗衣机,k 个烘干机.每个洗衣机和烘干机需要不同的时间.问 n 件 ...
- ZROI week1
\[ZROI day1\] \[Grid\] 题目描述 给定一个矩阵,小写字母,求一条路径使得从\((1,1) -> (n,m)\),字典序最小,并且每次只能向右或者向下. 题解 先考虑如果没有 ...
- 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 ...
随机推荐
- 【Python】使用scatter()绘制散点图
绘制简单散点图 要绘制单个点,使用scatter()函数,并向它传递一对x和y坐标,它将在指定位置绘制一个点 import matplotlib.pyplot as plt plt.scatter(2 ...
- nginx+keepalived实现双机热备高可用性
搭建准备: 机器两台 ip分别为192.168.100.128 192.168.100.129(能够用虚拟机測试.虚拟机网络模式为NET模式.且为静态ip) 另外须要准备一个虚拟ip对外提供服务.即通 ...
- 导出数据生成Excel(MVC)
/// <summary> /// 生成Excel /// </summary> /// <returns></returns> public File ...
- Oracle 中session和processes的初始设置
http://blog.163.com/succu/blog/static/193917174201252911727149/ 1.sessions 在初始化参数所设定的限制中,最为人所知的估计就 ...
- iPhone换电池是原装电池好还是换第三方大容量电池好?
转:https://www.xianjichina.com/news/details_60791.html 最近这段时间苹果降速门事件持续发酵,闹得满城风雨.尽管苹果公司两次致歉,很多果粉都去更换电池 ...
- Centos 6.X noVNC+websockify 实现webvnc
文章参考:https://github.com/kanaka/noVNC http://www.cnblogs.com/yanghuahui/p/3574388.html 工作原理: noVNC 可以 ...
- 深入Asyncio(一)入门介绍
介绍 Asyncio试图解决什么问题? 对于IO负载,有且仅有两个理由使用基于asyncio的并发而不是基于多线程的并发: 1. Asyncio为抢占式多任务(线程)提供了一个更安全的替代方案,避免了 ...
- 【caffe】Caffe的Python接口-官方教程-01-learning-Lenet-详细说明(含代码)
01-learning-Lenet, 主要讲的是 如何用python写一个Lenet,以及用来对手写体数据进行分类(Mnist).从此教程可以知道如何用python写prototxt,知道如何单步训练 ...
- EasyDSS RTMP流媒体服务器的HTTP接口query url的C++实现方法
EasyDSS支持HTTP GET接口访问,我们需要获取url的各种参数信息 比如http://ip:port/action?a=1&b=2&c=3 我们需要知道对应的a.b.c的值 ...
- Centos7重新安装yum
Centos7重新安装yum rpm -qa|grep yum 然后用下面的命令删除出现的xxx包: rpm -e --nodeps xxx 下载 python-urlgrabber-3.10-8.e ...