题意:给n个人m个星球,每个人适不适合去某个星球,每个星球的最大容量,看能不能满足所有人能去一个星球

题解:可以看出如果直接建边,边的个数是1e5左右的,这样时间肯定会爆掉,那么我们考虑用二进制状态压缩,对于能去相同的星球的全部压缩成一个点,和星球连边,权值为能去的个数,然后这样就只有(1<<10)个左右,(其实是队友想出来的做法= =),星球连向汇点,权值为星球容量,然后跑最大流就好了

#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 20090717
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1 using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f; struct edge{
int to,Next,c;
}e[maxn];
int s,t,cnt,head[N],dis[N];
int num[N];
void add(int u,int v,int c)
{
e[cnt].to=v;
e[cnt].c=c;
e[cnt].Next=head[u];
head[u]=cnt++;
e[cnt].to=u;
e[cnt].c=;
e[cnt].Next=head[v];
head[v]=cnt++;
}
bool bfs()
{
memset(dis,-,sizeof dis);
dis[s]=;
queue<int>q;
q.push(s);
while(!q.empty())
{
int x=q.front();
q.pop();
for(int i=head[x];~i;i=e[i].Next)
{
int te=e[i].to;
if(dis[te]==-&&e[i].c>)
{
dis[te]=dis[x]+;
q.push(te);
}
}
}
return dis[t]!=-;
}
int dfs(int x,int mx)
{
if(x==t)return mx;
int flow=;
for(int i=head[x];~i;i=e[i].Next)
{
int te=e[i].to,f;
if(dis[te]==dis[x]+&&e[i].c>&&(f=dfs(te,min(mx-flow,e[i].c))))
{
e[i].c-=f;
e[i^].c+=f;
flow+=f;
}
}
if(!flow)dis[x]=-;
return flow;
}
int max_flow()
{
int ans=,f;
while(bfs())
{
while((f=dfs(s,inf)))ans+=f;
}
return ans;
}
void init()
{
memset(head,-,sizeof head);
memset(num,,sizeof(num));
cnt=;
}
int main()
{
/*ios::sync_with_stdio(false);
cin.tie(0);*/
int n,m;
while(~scanf("%d%d",&n,&m))
{
init();
s=,t=;
for(int i=;i<=n;i++)
{
int q=;
for(int j=;j<m;j++)
{
int a;
scanf("%d",&a);
q+=a*(<<j);
} num[q]++;
}
for(int i=;i<;i++)add(s,i,num[i]);
for(int i=;i<;i++)
{
for(int j=;j<=;j++)
{
//if(i==463)printf("%d**\n",j);
if((i>>j)&) add(i,+j+,inf);
}
}
for(int j=;j<=m;j++)
{
int a;
scanf("%d",&a);
add(+j,t,a);
}
if(max_flow()==n)puts("YES");
else puts("NO");
}
return ;
}
/********************
1,2,3,4,5,6,9,18
********************/

hdu3605最大流的更多相关文章

  1. hdu3605(最大流+状态压缩)

    传送门:Escape 题意:给出每个人适合住的星球信息和该星球能住多少人 ,第一行给出n m 代表有 n 个人 m 个星球,然后接下来n行每行m个数字 1代表适合第 i 个星球 0 代表不适合第 i ...

  2. 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 ...

  3. HDU3605:Escape(状态压缩+最大流)

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

  4. HDU3605(KB11-M 状态压缩+最大流)

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

  5. HDU- 3605 - Escape 最大流 + 二进制压位

    HDU - 3605 : acm.hdu.edu.cn/showproblem.php?pid=3605 题目: 有1e5的的人,小于10个的星球,每个星球都有容量,每个人也有适合的星球和不适合的星球 ...

  6. HDU3605 Escape(最大流判满流 + 状压)

    [题意]: 有N个人,M个星球,给N*M矩阵,(i, j)为1代表i可以到j星球,0代表不能,问是否能把所有人转移走. [思路]: N的范围为1e6,如果让每个人与星球连边一定TLE,再根据矩阵每一行 ...

  7. HDU3605: Escape-二进制优化建图-最大流

    目录 目录 思路: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 目录 题意:传送门  原题目描述在最下面.  \(n(n\leq 100000)\)个人\(m(m\leq 10) ...

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

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

  9. HDU-3605-Escape(最大流, 状态压缩)

    链接: https://vjudge.net/problem/HDU-3605 题意: 2012 If this is the end of the world how to do? I do not ...

随机推荐

  1. vertical-align:middle;一般用于img和行内文字对齐方式

    vertical-align:top ;文字和行内块元素的顶部对齐 vertical-align:middle;居中 vertical-align:bottom;底对齐

  2. Python 中星号作用:解包&打散

    python中’*’和’**’的使用分两个方面,一个是计算,另一个是参数传递过程中元素的打包和解包.  计算方面 ‘*’和’**’在python中最常见的作用分别是‘相乘’和‘乘幂’,如下: > ...

  3. if控制器+循环控制器+计数器,控制接口分支

    但是我不想这么做,接口只想写一次,让循环控制器和if控制器去判断接口,执行我想要的分支.这里遇到了一个问题,if控制器通过什么去判断接下来的分支?我引入了一个计数器的概念.起始值为0,每次循环加1,将 ...

  4. 如何删除github中的仓库?

    使用Github管理项目确实有些好处,但删除仓库(repositories)确实不太好找到. 首先进入要删除的仓库,点击右下角的“settings” 然后拉到页面最下面在danger zone 按“d ...

  5. self-awareness is key in changing the way you think

    1: controlling the way you think is a manageable process The good news is that you have control over ...

  6. LeetCode:分割链表【86】

    LeetCode:分割链表[86] 题目描述 给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前. 你应当保留两个分区中每个节点的初始相对位置. 示例 ...

  7. JavaScript:基础扩展(1)——JSON

    JavaScript:扩展知识(1)——JSON 理解: 关于 JSON,最重要的是要理解它是一种数据格式,不是一种编程语言.虽然具有相同的语法形式,但 JSON 并不从属于 JavaScript.而 ...

  8. ZOJ 3959 Problem Preparation 【水】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3959 AC代码 #include <cstdio> ...

  9. Ag-grid控件使用pine:left后,配合iview下拉框,会出现闪烁

    Ag-grid控件使用pinned:left后,配合iview下拉框,会出现闪烁 引起原因:下拉图标的反转动画 目前解决方案: 添加一个全局样式: 禁用动画,其他地方也是如此, 影响控件有:gz-tr ...

  10. 解决Ubuntun 12.04编译Mesa10.3 WARNING: 'aclocal-1.14' is missing on your system

    安 装Mesa时,最后一个错误报“WARNING: 'aclocal-1.14' is missing on your system.”,虽然是个Warning,但是无法进行下一步make,所以必须解 ...