网络流 HDU 3605
建图 源点 -> 1024类人 -> 星球 -> 汇点
权 每类人数目 星球容量 星球容量
列举 0~1024 一位是1 那么和对应的星球建边
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<queue>
#include<math.h> using namespace std;
#define inf 100000000
int z[];
int vis[];
int head[];
int y[];
int cnt,S,T;
struct edg
{
int w,next,to; }x[];
void add(int u,int v,int w)
{
x[cnt].next=head[u];
x[cnt].to=v;
x[cnt].w=w;
head[u]=cnt++;
}
int bfs()
{
memset(vis,-,sizeof(vis));
queue<int>q1;
q1.push(S);
vis[S]=;
int j; while(!q1.empty())
{
int now=q1.front();
q1.pop();
for(j=head[now];j!=-;j=x[j].next)
{
if(vis[x[j].to]<&&x[j].w)
{ vis[x[j].to]=vis[now]+;
q1.push(x[j].to);
}
}
}
return vis[T]!=-;
}
int dfs(int u,int w)
{
int ans=; if(u==T)
return w;
int j;
for(j=head[u];j!=-;j=x[j].next)
{
if(vis[x[j].to]==vis[u]+&&x[j].w)
{ int b=dfs(x[j].to,min(w-ans,x[j].w));
ans=ans+b;
x[j].w-=b;
x[j^].w+=b;
}
}
return ans;
}
int main()
{
int n,m; while(scanf("%d%d",&n,&m)!=EOF)
{
int i,j;
memset(z,,sizeof(z)); for(i=;i<=n;i++)
{
int b=; for(j=;j<=m;j++)
{
int a;
scanf("%d",&a);
if(a==)b=b+(<<(j-));
}
z[b]++;
}
for(i=;i<=m;i++)
scanf("%d",&y[i]);
S=;
T=; //这2个点只要没用过就行
cnt=;
memset(head,-,sizeof(head));
for(i=;i<=;i++)
{
if(z[i])
{
add(S,i,z[i]);
add(i,S,);
}
} //0 1024 人的下标 1025 1035 星球下标
for(i=;i<=;i++)
{
if(z[i])
{
for(j=;j<=m;j++)
{
if(<<(j-)&i)
{
add(i,+j,y[j]);
add(+j,i,);
}
}
}
} for(j=;j<=m;j++)
{
add(+j,T,y[j]);
add(T,+j,);
} int ans=;
while(bfs())
ans+=dfs(S,inf);
if(ans>=n)
printf("YES\n");
else
printf("NO\n");
} return ;
}
网络流 HDU 3605的更多相关文章
- HDU 3605 Escape (网络流,最大流,位运算压缩)
HDU 3605 Escape (网络流,最大流,位运算压缩) Description 2012 If this is the end of the world how to do? I do not ...
- Hdu 3605 Escape (最大流 + 缩点)
题目链接: Hdu 3605 Escape 题目描述: 有n个人要迁移到m个星球,每个星球有最大容量,每个人有喜欢的星球,问是否所有的人都能迁移成功? 解题思路: 正常情况下建图,不会爆内存,但是T ...
- HDU 3605 Escape(状压+最大流)
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Sub ...
- 网络流 HDU 3549 Flow Problem
网络流 HDU 3549 Flow Problem 题目:pid=3549">http://acm.hdu.edu.cn/showproblem.php?pid=3549 用增广路算法 ...
- 网络流 E - Escape HDU - 3605
2012 If this is the end of the world how to do? I do not know how. But now scientists have found tha ...
- HDU 3605:Escape(最大流+状态压缩)
http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...
- HDU(3605),二分图多重匹配
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 4000/2000 MS (Java/Others) ...
- HDU 3605
http://acm.hdu.edu.cn/showproblem.php?pid=3605 用最大流做的,G++超时,C++可以过,看别人写的叫二分图多重匹配,还不会这玩意一会学学 显然的最大流模型 ...
- HDU 3605 Escape(状态压缩+最大流)
http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意: 有n个人和m个星球,每个人可以去某些星球和不可以去某些星球,并且每个星球有最大居住人数,判断是否所 ...
随机推荐
- Application中的路径
前提条件 项目工程目录:E:/Work/cosmosbox/cb-client/ 我电脑当前的用户名:qingqing PersistentDataPath Application.persisten ...
- Unity3D FPS帧数修改
修改Unity的FPS FPS是游戏运行的帧数,本文讲解如何修改Unity引擎的FPS. 步骤 1.在 Edit/Project Settings/Quality 质量设置里把帧数设定关闭,关闭之后 ...
- IIS7.5中神秘的ApplicationPoolIdentity
IIS7.5中(仅win7,win2008 SP2,win2008 R2支持),应用程序池的运行帐号,除了指定为LocalService,LocalSystem,NetWorkService这三种基本 ...
- GNU make简要介绍①指定变量、自动推导规则、清除工作目录过程文件
Makefile简介 在执行make之前需要一个命名为Makefile的特殊文件来告诉make需要做些什么. 当使用 make 工具进行编译时,工程中以下几种文件在执行 make 时将会被编译 (重新 ...
- 获取assemblies信息in .net core
using System; using System.Linq; using System.Reflection; using System.Runtime.Loader; using Microso ...
- 关于codeMirror插件使用的一个坑
codeMirror插件可以做语法高亮渲染,但它操作过程是这样的:先从 textarea中读取值放到codemirror动态生成的div中,根据textarea中的换行个数确定行数,根据正则表达来高亮 ...
- [转]PHP 下使用 ZeroMQ 和 protobuf
FROM : http://www.68idc.cn/help/makewebs/php/20150118175432.html 前言 这个记录总的来说分两部分: 搭建环境. 简单使用教程. 搭建环境 ...
- K8 系统中省市县数据表的设计可以反映出什么? 通过一个基础业务表的设计品味软件系统的整体架构
1:没有严谨的Id思想,不变化的Id思想,看不见的Id的思想. 2:数据不严谨,没有上下级关系,没有树形结构,ParentId 的思想. 3:表之间的关系都是弱关联,基础数据一修改业务数据就容易乱套. ...
- mybatis 3.2.7 与 spring mvc 3.x、logback整合
github上有一个Mybatis-Spring的项目,专门用于辅助完成mybatis与spring的整合,大大简化了整合难度,使用步骤: 准备工作: maven依赖项: <properties ...
- ASP.NET MVC 关闭 客户端 xss 检查
为防止 XSS 攻击,asp.net 机制 会默认检测 请求报文 内是否有包含html标签,以提醒开发人员处理,报错如下:"从客户端中检测到有潜在危险的Request...值"当我 ...