这题的做法非常直观,却又非常不直观

先容许我吐一下槽吧~作者你的英语是读到火星上去了喵?

题目大体是说人类要移民,然后有 n 个人, m 个星球

每个人都有 m 个 0 、 1 数码表示他能否移民到该星球,每个星球有个最大人口容量

问是否有方案移民该 n 个人

乍一看很水,但是看看 n 的数据范围真是太感动人心了,有种这尼玛更本不是网络流的感脚——

但是 m 的范围只有 10 !直觉告诉我似乎可以动手脚的样子喵?

状压!因为不需要输出方案,所以两个可移民方案相同的人完全可以视为同一人

然后点就被压到了 1024 以内,妥妥地过掉了~

我才不会说我连边连错害我调了半小时呢喵

 #include <cstdio>
#include <cstring>
#define min(x, y) ((x)<(y) ? (x):(y))
const int inf=0x7FFFFFFF;
const int sizeOfPoint=;
const int sizeOfEdge=; int n, m, t;
int S, T;
int f[sizeOfPoint], a[sizeOfPoint]; struct edge {int point, flow; edge * next, * pair;};
edge memory[sizeOfEdge], * port=memory;
edge * e[sizeOfPoint];
inline void clear() {port=memory; memset(e, , sizeof e); t=; memset(f, , sizeof f);}
inline edge * newedge(int point, int flow, edge * next) {edge * ret=port++; ret->point=point; ret->flow=flow; ret->next=next; ret->pair=NULL; return ret;}
inline void build(int u, int v, int f) {e[u]=newedge(v, f, e[u]); e[v]=newedge(u, , e[v]); e[u]->pair=e[v]; e[v]->pair=e[u];}
int h[sizeOfPoint];
inline bool bfs();
inline int aug();
inline int dinic(); int main()
{
int x, state; while (scanf("%d %d", &n, &m)!=EOF)
{
clear();
for (int i=;i<=n;i++)
{
state=;
for (int j=;j<m;j++)
{
scanf("%d", &x);
state|=x<<j;
}
if (!f[state]++) a[++t]=state;
}
S=; T=t+m+;
for (int i=;i<=t;i++)
{
build(S, i, f[a[i]]);
for (int j=;j<m;j++) if ((a[i]>>j)&)
build(i, t+j+, f[a[i]]);
}
for (int i=;i<=m;i++)
{
scanf("%d", &x);
build(t+i, T, x);
} if (dinic()==n) printf("YES\n");
else printf("NO\n");
} return ;
}
inline bool bfs()
{
static int q[sizeOfPoint];
int l=, r=;
memset(h, 0xFF, sizeof h); h[T]=;
for (q[r++]=T;l<r;l++)
{
int u=q[l];
for (edge * i=e[u];i;i=i->next) if (i->pair->flow && h[i->point]==-)
h[q[r++]=i->point]=h[u]+;
}
return h[S]>=;
}
inline int aug()
{
static edge * t[sizeOfPoint], * path[sizeOfPoint];
static int aug[sizeOfPoint];
int flow=; memcpy(t, e, sizeof e);
memset(path, , sizeof path);
memset(aug, , sizeof aug);
aug[S]=inf;
for (int u=S; ; )
{
if (u==T)
{
flow+=aug[T];
for (edge * i=path[T];i;i=path[i->point])
{
i->pair->flow-=aug[T], i->flow+=aug[T];
aug[i->point]-=aug[T];
if (!aug[i->point]) h[i->point]=-;
}
u=S;
} edge *& i=t[u];
for ( ;i && (!i->flow || h[u]!=h[i->point]+);i=i->next);
if (i)
{
path[i->point]=i->pair; aug[i->point]=min(aug[u], i->flow);
u=i->point; i=i->next;
}
else
{
if (u==S) break;
u=path[u]->point;
}
} return flow;
}
inline int dinic()
{
int ret=, flow;
while (bfs())
while (flow=aug())
ret+=flow;
return ret;
}

本傻调出翔系列

[hdu 3605]Escape的更多相关文章

  1. HDU 3605 Escape (网络流,最大流,位运算压缩)

    HDU 3605 Escape (网络流,最大流,位运算压缩) Description 2012 If this is the end of the world how to do? I do not ...

  2. Hdu 3605 Escape (最大流 + 缩点)

    题目链接: Hdu 3605  Escape 题目描述: 有n个人要迁移到m个星球,每个星球有最大容量,每个人有喜欢的星球,问是否所有的人都能迁移成功? 解题思路: 正常情况下建图,不会爆内存,但是T ...

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

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

  4. HDU 3605 Escape 最大流+状压

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

  5. hdu 3605 Escape 二分图的多重匹配(匈牙利算法)

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

  6. HDU 3605 Escape(状态压缩+最大流)

    http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意: 有n个人和m个星球,每个人可以去某些星球和不可以去某些星球,并且每个星球有最大居住人数,判断是否所 ...

  7. HDU 3605 Escape(二分图多重匹配问题)

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

  8. HDU - 3605 Escape (缩点+最大流/二分图多重匹配)

    题意:有N(1<=N<=1e5)个人要移民到M(1<=M<=10)个星球上,每个人有自己想去的星球,每个星球有最大承载人数.问这N个人能否移民成功. 分析:可以用最大流的思路求 ...

  9. HDU 3605 Escape 最大流

    题意: 如果这是2012年世界末日怎么办?我不知道该怎么做.但是现在科学家们已经发现,有些星球上的人可以生存,但有些人却不适合居住.现在科学家们需要你的帮助,就是确定所有人都能在这些行星上生活.输入多 ...

随机推荐

  1. poj2137 dp

    //Accepted 228K 32MS //dp[k][i][j] 表示从1的k号节点到i的j号节点的最小花费 //dp[k][i][j]=min(dp[k][i-1][h]+cost) cost为 ...

  2. C#导入EXCEL数据

    public static void InputUserFromExcel(string filePath) { string FileExName = filePath.Substring(file ...

  3. wMy_Python ~储存相关~

    str,int,list,tuple,dict 是类型调用之后会产生一个 实例 >>> brand=["李宁",'耐克','阿迪达斯','鱼C'] >> ...

  4. BigBlueButton的安装

    下来VM文件,打开系统后 sudo apt-get updatesudo apt-get upgradesudo apt-get dist-upgrade sudo apt-get install b ...

  5. 【LeetCode】Best Time to Buy and Sell Stock IV

    Best Time to Buy and Sell Stock IV Say you have an array for which the ith element is the price of a ...

  6. .NET的语法优化

    1.多参数 判断 条件 //判断 var fileKey = new { DateStart = search.DateStart.IsNull(), //关开始时间 DateEnd = search ...

  7. 使用RBL拦截垃圾邮件

    1.   sbl-xbl.spamhaus.org  2    bl.spamcop.net  3    zen.spamhaus.org

  8. 3、SQL基础整理(分组)

    分组 group by select class from xuesheng group by class select class,AVG(chinese)from xuesheng group b ...

  9. MVC - Code First Migration Command line

    当开发MVC应用程序, 使用.NET Entity Framework的Code First model试, 若是需要将model层对象的改动更新进数据库, 需要使用Package Manager C ...

  10. Ubuntu 14.04 AM335x TI-RTOS 编译

    /************************************************************************************* * Ubuntu 14.0 ...