Escape

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 9430    Accepted Submission(s): 2234

Problem Description
2012 If this is the end of the world how to do? I do not know how. But now scientists have found that some stars, who can live, but some people do not fit to live some of the planet. Now scientists want your help, is to determine what all of people can live in these planets.

 
Input
More set of test data, the beginning of each data is n (1 <= n <= 100000), m (1 <= m <= 10) n indicate there n people on the earth, m representatives m planet, planet and people labels are from 0. Here are n lines, each line represents a suitable living conditions of people, each row has m digits, the ith digits is 1, said that a person is fit to live in the ith-planet, or is 0 for this person is not suitable for living in the ith planet.
The last line has m digits, the ith digit ai indicates the ith planet can contain ai people most..
0 <= ai <= 100000

 
Output
Determine whether all people can live up to these stars
If you can output YES, otherwise output NO.

 
Sample Input
1 1
1
1
 
2 2
1 0
1 0
1 1
 
Sample Output
YES
NO
 

题目链接:HDU 3605

比较入门的一道最大流,显然可以想到是超级源点S->人连一条为流量1的边;人->可达的星球连一条流量为1的边;星球->超级汇点T连一条容量为给定的星球容量的边。但是这样就超时了。

膜了一下正确的做法,因为星球数不超过10,显然一个人的选择状态最多$2^{10}=1024$种,然后就把状态代替了人,因此上面的建图中把人改为二进制的状压转化为10进制的数值i即可,当然与人有关的流量也不再是1,而是同一状态下的人数

代码:

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define CLR(arr,val) memset(arr,val,sizeof(arr))
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
typedef pair<int,int> pii;
typedef long long LL;
const double PI=acos(-1.0);
const int S=1050;
struct edge
{
int to,nxt;
int cap;
};
edge E[S*23];
int head[S],tot;
bitset<S> vis;
int st[S]; void init()
{
CLR(head,-1);
tot=0;
CLR(st,0);
}
inline void add(int s,int t,int c)
{
E[tot].to=t;
E[tot].cap=c;
E[tot].nxt=head[s];
head[s]=tot++; E[tot].cap=0;
E[tot].to=s;
E[tot].nxt=head[t];
head[t]=tot++;
}
int dfs(int s,int t,int f)
{
if(s==t)
return f;
vis[s]=1;
for (int i=head[s]; ~i; i=E[i].nxt)
{
int v=E[i].to;
if(!vis[v]&&E[i].cap>0)
{
int d=dfs(v,t,min(f,E[i].cap));
if(d>0)
{
E[i].cap-=d;
E[i^1].cap+=d;
return d;
}
}
}
return 0;
}
int max_flow(int s,int t)
{
int ret=0;
int f;
while (true)
{
vis.reset();
f=dfs(s,t,INF);
if(!f)
break;
ret+=f;
}
return ret;
}
int main(void)
{
int n,m,i,j,c,s;
while (~scanf("%d%d",&n,&m))
{
init();
int S=0;
int T=(1<<m)+m;
for (i=1; i<=n; ++i)
{
int S=0;
for (j=0; j<m; ++j)
{
scanf("%d",&s);
if(s)
S|=(1<<j);
}
++st[S];
}
int R=1<<m;
for (i=1; i<R; ++i)
{
if(st[i])
{
add(S,i,st[i]);
for (j=0; j<m; ++j)
{
if(i&(1<<j))
add(i,R+j,st[i]);
}
}
}
for (i=0; i<m; ++i)
{
scanf("%d",&c);
add(R+i,T,c);
}
puts(max_flow(S,T)==n?"YES":"NO");
}
return 0;
}

HDU 3605 Escape(状压+最大流)的更多相关文章

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

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

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

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

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

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

  4. HDU 3605 Escape 最大流+状压

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

  5. HDU 4284Travel(状压DP)

    HDU 4284    Travel 有N个城市,M条边和H个这个人(PP)必须要去的城市,在每个城市里他都必须要“打工”,打工需要花费Di,可以挣到Ci,每条边有一个花费,现在求PP可不可以从起点1 ...

  6. hdu 2209 bfs+状压

    http://acm.hdu.edu.cn/showproblem.php?pid=2209 不知为啥有种直觉.会出状压+搜索的题,刷几道先 简单的BFS.状压表示牌的状态, //#pragma co ...

  7. hdu 5025 bfs+状压

    http://acm.hdu.edu.cn/showproblem.php?pid=5025 N*N矩阵 M个钥匙 K起点,T终点,S点需多花费1点且只需要一次,1-9表示9把钥匙,只有当前有I号钥匙 ...

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

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

  9. HDU 4336 容斥原理 || 状压DP

    状压DP :F(S)=Sum*F(S)+p(x1)*F(S^(1<<x1))+p(x2)*F(S^(1<<x2))...+1; F(S)表示取状态为S的牌的期望次数,Sum表示 ...

随机推荐

  1. 【Alpha】Daily Scrum Meeting第十次

    一.本次Daily Scrum Meeting主要内容 每个人学习情况 测试的任务的安排 Alpha版本展示的具体内容 二.任务安排 学号尾数 昨天做的任务 今天做的任务 任务用时 612 完成将计时 ...

  2. 进阶系列一【绝对干货】---SQL语句执行效率优化

    1.尽量适用联接查询来取代子查询 2.如果要用子查询,用EXISTS替代IN.用NOT EXISTS替代NOT IN,因为EXISTS引入的子查询只是测试是否存在符合子查询中指定条件的行,效率较高.无 ...

  3. 安卓APP关于切图标

    bin res drawable-hdpi drawable-ldpi drawable-mdpi drawable-nodpi drawable-xhdpi drawable-xxhdpi x越大代 ...

  4. [教程] 【玩转终端1:apt-get】

    进来工作比较清闲,所以写点东西,给喜欢折腾的朋友.本文及后面将要介绍的一些终端命令,其实对于玩过linux的人来说,是很基础的东西,我可能是班门弄斧了(拍砖的请轻点,有愿意补充/纠正的,本人求知不得) ...

  5. 【krpano】浏览点赞插件1.1(源码+介绍+预览)

    插件使用说明详见:http://www.cnblogs.com/reachteam/p/5479068.html 插件更新 1.新增测试模式 用户可以使用uid="test"进行本 ...

  6. 在测试框架中使用Log4J 2

    之前的测试框架:http://www.cnblogs.com/tobecrazy/p/4553444.html 配合Jenkins可持续集成:http://www.cnblogs.com/tobecr ...

  7. JS面试题-算法台阶问题

    有100格台阶,可以跨1步可以跨2步,那么一个有多少种走法: 今天电话面试.遇到一道算法问题,然后瞬间一脸懵逼: 然后机智的我,自作聪明的想到如果一个人每次都走1步,那么最多步,每次走2步最少步:然后 ...

  8. 微信开发之Author网页授权

     微信开发中,经常有这样的需求:获得用户头像.绑定微信号给用户发信息.. 那么实现这些的前提就是授权!   1.配置安全回调域名: 在微信公众号请求用户网页授权之前,开发者需要先到公众平台官网中的&q ...

  9. Select查询执行顺序

    链接:http://blog.jobbole.com/55086/ 很多程序员视 SQL 为洪水猛兽.SQL 是一种为数不多的声明性语言,它的运行方式完全不同于我们所熟知的命令行语言.面向对象的程序语 ...

  10. Oracle 11g新特性延迟段创建和truncate的增强

    下面测试Oracle 11g开始的新特性truncate的增强和延迟段空间创建. Oracle从11g开始,当用户创建一张空表的时候不会先分配段和空间,只有当对这张表插入第一行数据的时候才分配段和空间 ...