【题意】:

有N个人,M个星球,给N*M矩阵,(i, j)为1代表i可以到j星球,0代表不能,问是否能把所有人转移走。

【思路】:

N的范围为1e6,如果让每个人与星球连边一定TLE,再根据矩阵每一行只有0,1可以进行状压,把相同状态idx的人合并到数组siz[idx],

在扫描状态,与符合条件的星球连边。

【建图】:

超级源点sp -> idx  边权siz[idx]

idx -> M  边权inf

M -> 超级汇点tp  边权为容量

#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + ;
const int maxm = + ;
const int inf = 0x3f3f3f3f;
int n, m, d[maxn+maxm], siz[maxn];
int head[maxn+maxm], tot, maxflow;
int sp, tp;
struct edge{
int to, w, next;
} ed[(maxn*maxm+maxn+maxm)<<];
inline void init(){
memset( head ,-, sizeof(head) );
memset( siz, , sizeof(siz) );
tot = ;
} inline void add( int u, int v, int w ){
ed[++tot].to = v; ed[tot].w = w; ed[tot].next = head[u]; head[u] = tot;
ed[++tot].to = u; ed[tot].w = ; ed[tot].next = head[v]; head[v] = tot;
} inline bool bfs(){
memset( d, , sizeof(d) );
queue<int> q;
d[sp] = ;
q.push(sp);
while( !q.empty() ){
int x = q.front();
q.pop();
for( int i=head[x]; i!=-; i=ed[i].next ){
int y = ed[i].to;
if( ed[i].w && !d[y] ){
d[y] = d[x] + ;
q.push(y);
if( y==tp ) return ;
}
}
}
return ;
} inline int dfs( int x, int flow ){
if( x==tp ) return flow;
int res = flow, k;
for( int i=head[x]; i!=- && res; i=ed[i].next ){
int y = ed[i].to;
if( ed[i].w && d[y]==d[x]+ ){
k = dfs( y, min( ed[i].w, res ) );
if(!k) d[y] = ;
ed[i].w -= k;
ed[i^].w += k;
res -= k;
}
}
return flow-res;
} inline void dinic(){
int flow = maxflow = ;
while( bfs() )
while( flow=dfs(sp, inf) ) maxflow += flow;
} int main(){
// freopen("in.txt", "r", stdin);
while( ~scanf("%d%d", &n, &m) ){
init();
int l = inf, r = -inf;
for( int i=; i<=n; i++ ){
int sum = ;
for( int j=; j<=m; j++ ){
int tmp;
scanf("%d", &tmp);
sum <<= ;
sum += tmp;
}
siz[sum] ++;
l = min( l, sum ); r = max( r, sum );
}
sp = ;
tp = r+m+;
for( int i=; i<=m; i++ ){
int cont;
scanf("%d", &cont);
add( i+r, tp, cont );
}
for( int i=l; i<=r; i++ )
if( siz[i] ){
int pos = ;
while( pos<m ){
if( i&(<<pos) ) add( i, m-pos+r, inf );
pos ++;
}
add( sp, i, siz[i] );
}
dinic();
if( n<=maxflow ) puts("YES");
else puts("NO");
} return ;
}

HDU3605 Escape(最大流判满流 + 状压)的更多相关文章

  1. hdu3605 Escape 二分图多重匹配/最大流

    2012 If this is the end of the world how to do? I do not know how. But now scientists have found tha ...

  2. hdu 3572 最大流判断满流

    #include<stdio.h> #include<string.h> #include<queue> using namespace std; #define ...

  3. HDU2883 kebab(最大流判断满流 + 离散化 + 区间化点)

    [题意]: 有一个烤箱,烤箱在一个时刻最多考M个肉串,N个顾客,每个顾客有属性s,n,e,t s是来的时间,n是想要的肉串数量,e是最晚离开的时间,t是烤的时间(几分熟). 顾客的烤肉可以分开烤,比如 ...

  4. HDU 4888 Redraw Beautiful Drawings(最大流+判最大流网络是否唯一)

    Problem Description Alice and Bob are playing together. Alice is crazy about art and she has visited ...

  5. HDU 3572 Task Schedule(最大流判断满流)

    https://vjudge.net/problem/HDU-3572 题意: 有N个作业和M台机器,每个作业都有一个持续时间P,工作的日期为S~E.作业可以断断续续的在不同机器上做,每台机器每次只可 ...

  6. hdu-3572 Task Schedule---最大流判断满流+dinic算法

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3572 题目大意: 给N个任务,M台机器.每个任务有最早才能开始做的时间S,deadline E,和持 ...

  7. hdu3572 任务分配/最大流判断满流

    题意:将n个任务分配为m个机器,给每个任务需要的天数(无需每天连续),和可以在哪些天去做该任务,求是否存在方案. 典型的任务(X)----天(Y)二分最大流,(因为这里任务是与天的关系)处理器控制流量 ...

  8. HDU 3605 Escape(状压+最大流)

    Escape Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Sub ...

  9. HDU 3605 Escape 最大流+状压

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 2000/1000 MS (Java/Others)    ...

随机推荐

  1. Linux上安装git并在gitlab上建立对应的项目

    1.CentOS上面安装git我所用的CentOS为CentOS6.5,其他版本没有测试. yum install git 安装之后查看git版本信息 git --version 2.配置git信息g ...

  2. Java集合详解1:一文读懂ArrayList,Vector与Stack使用方法和实现原理

    本文非常详尽地介绍了Java中的三个集合类 ArrayList,Vector与Stack <Java集合详解系列>是我在完成夯实Java基础篇的系列博客后准备开始写的新系列. 这些文章将整 ...

  3. 停止IIS服务

    1 第一步 停止 World Wide Web Publishing Service     这个是W3C服务 2 第二部 停止 IIS Admin Service  这个IIS元数据管理服务

  4. 关于深度学习框架 TensorFlow、Theano 和 Keras

    [TensorFlow] ——( https://morvanzhou.github.io/tutorials/machine-learning/tensorflow/) 1.TensorFlow是啥 ...

  5. 用Python 绘制分布(折线)图

    用Python 绘制分布(折线)图,使用的是 plot()函数. 一个简单的例子: # encoding=utf-8 import matplotlib.pyplot as plt from pyla ...

  6. kubernetes学习一:安装及部署第一个Web应用

    准备工作 首先准备Kubernets的环境,使用的是centos7.5 关闭防火墙: # systemctl disable firewalld # systemctl stop firewalld ...

  7. ReentrantReadWriteLock源码分析

    代码在后面 读锁 = 共享锁 读锁写锁,公用一个Sync AQS state. 写锁是排他的,看到有人获取锁,他不会去获取,他获取了锁,别人也不会进来获取锁. 写锁的获取跟ReentarntLock一 ...

  8. history 用法大全

     history 命令用于显示指定数目的指令命令,读取历史命令文件中的目录到历史命令缓冲区和将历史命令缓冲区中的目录写入命令文件.   语法 history  [options]  [file]   ...

  9. [转帖]Hikari 数据源介绍

    Hikari 数据源介绍 jimmy・2018 年 09 月 23 日・默认分类 预估 https://izhong.me/index.php/archives/78/ 介绍 官网地址: https: ...

  10. DataTable Linq Group Count where写法

    DataTable dataTable = new DataTable(); dataTable.Columns.Add("username", typeof(string)); ...