链接:

https://vjudge.net/problem/HDU-3605

题意:

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.

思路:

1e5个人,每个人都连边会T, 考虑每个人的状态,选10个星球,最多1024中选择,吧人转换程选择,压缩成1024中情况.

连到星球,在跑最大流即可.

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL; const int MAXN = 1e4+10;
const int INF = 1e9; struct Edge
{
int from, to, cap;
};
vector<Edge> edges;
vector<int> G[MAXN];
int Dis[MAXN], Vis[MAXN];
int Peo[MAXN];
int n, m, s, t, d; void AddEdge(int from, int to, int cap)
{
edges.push_back(Edge{from, to, cap});
edges.push_back(Edge{to, from, 0});
G[from].push_back(edges.size()-2);
G[to].push_back(edges.size()-1);
} bool Bfs()
{
//Bfs构造分层网络
memset(Dis, -1, sizeof(Dis));
queue<int> que;
que.push(s);
Dis[s] = 0;
while (!que.empty())
{
int u = que.front();
que.pop();
// cout << u << endl;
for (int i = 0;i < G[u].size();i++)
{
Edge & e = edges[G[u][i]];
if (e.cap > 0 && Dis[e.to] == -1)
{
que.push(e.to);
Dis[e.to] = Dis[u]+1;
}
}
}
return (Dis[t] != -1);
} int Dfs(int u, int flow)
{
//flow 表示当前流量上限
if (u == t)
return flow;
int res = 0;
for (int i = 0;i < G[u].size();i++)
{
Edge & e = edges[G[u][i]];
if (e.cap > 0 && Dis[u]+1 == Dis[e.to])
{
int tmp = Dfs(e.to, min(flow, e.cap)); // 递归计算顶点 v
flow -= tmp;
e.cap -= tmp;
res += tmp;
edges[G[u][i]^1].cap += tmp;
if (flow == 0)
break;
}
}
if (res == 0)
Dis[u] = -1;
return res;
} int MaxFlow()
{
int res = 0;
while (Bfs())
{
res += Dfs(s, INF);
}
return res;
} int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
while (cin >> n >> m)
{
memset(Peo, 0, sizeof(Peo));
s = 1023+m+1, t = 1023+m+2;
for (int i = 0;i <= t;i++)
G[i].clear();
edges.clear();
int w;
for (int i = 1;i <= n;i++)
{
int res = 0;
for (int j = 0;j < m;j++)
{
cin >> w;
res += (1<<j)*w;
}
// cout << res << endl;
Peo[res]++;
}
for (int i = 1;i <= m;i++)
{
cin >> w;
AddEdge(1023+i, t, w);
}
for (int i = 0;i <= 1023;i++)
{
if (Peo[i] == 0)
continue;
AddEdge(s, i, Peo[i]);
int tmp = i;
int cnt = 1;
while (tmp)
{
if (tmp&1)
{
AddEdge(i, 1023+cnt, Peo[i]);
}
tmp >>= 1;
cnt++;
}
}
int res = MaxFlow();
if (res == n)
cout << "YES" << endl;
else
cout << "NO" << endl;
} return 0;
}
/*
2 2
1 1
0 1
2 2
*/

HDU-3605-Escape(最大流, 状态压缩)的更多相关文章

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

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

  2. HDU 3605 Escape 最大流+状压

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

  3. HDU 3605 Escape 最大流

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

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

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

  5. hdu 5025 Saving Tang Monk 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...

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

    http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...

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

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

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

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

  9. HDU 1885 Key Task (BFS + 状态压缩)

    题意:给定一个n*m的矩阵,里面有门,有钥匙,有出口,问你逃出去的最短路径是多少. 析:这很明显是一个BFS,但是,里面又有其他的东西,所以我们考虑状态压缩,定义三维BFS,最后一维表示拿到钥匙的状态 ...

  10. HDU 3681 Prison Break(状态压缩dp + BFS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 前些天花时间看到的题目,但写出不来,弱弱的放弃了.没想到现在学弟居然写出这种代码来,大吃一惊附加 ...

随机推荐

  1. Salesforce学习之路-developer篇(五)一文读懂Aura原理及实战案例分析

    1. 什么是Lightning Component框架? Lightning Component框架是一个UI框架,用于为移动和台式设备开发Web应用程序.这是一个单页面Web应用框架,用于为Ligh ...

  2. Metinfo5.1 /member/getpassword.php SQL注入

  3. 查找两个有序数组中的第K个元素(find kth smallest element in 2 sorted arrays)

    查找两个有序数组中的第K个元素 int FindKth(int a[], int b[], int k, int astart, int aend, int bstart, int bend) { ; ...

  4. ASM下添加磁盘

    linux下asm磁盘扩容,此次扩容添加4块480G磁盘 第一步:multipath -ll : 查看多路径映射磁盘(两节点都做) 配置 /etc/multipath.conf文件,配置新加磁盘的al ...

  5. 软件设计分为结构化设计(SD)

    软件设计分为结构化设计(SD)与面向对象设计(OOD). 其中结构化设计SD是一种面向数据流的方法,它以SRS(软件需求规格说明书)和SA(结构化分析)阶段所产生的和数据字典等文档为基础,是一个自顶向 ...

  6. 第七次学习总结&&第五次实验报告

    一.实验目的 (1)理解抽象类与接口的使用: (2)了解包的作用,掌握包的设计方法. 二.实验要求 (1)掌握使用抽象类的方法. (2)掌握使用系统接口的技术和创建自定义接口的方法. (3)了解 Ja ...

  7. etcd常用命令-增删改查

    增删改查key-values 插入数据测试 # etcdctl put name1 james# etcdctl put name11 alice# etcdctl put name12 seli # ...

  8. Dubbo从入门到精通

    1.在Dubbo中注解的使用 2.Dubbo启动时qos-server can not bind localhost:22222错误解决 3.Dubbo配置方式详解

  9. Windows下备份mysql

    ---恢复内容开始---  Windows下备份mysql 第一步 编写脚本 ::设置时间变量 set "Ymd=%date:~0,4%%date:~5,2%%date:~8,2%%time ...

  10. Linux系统装mycat

    最近在Linux系统中装载了一下mycut,记录过程以及所遇到的异常 首先是mycut的压缩包,直接放到linux中解压即可 链接:https://pan.baidu.com/s/1qo7z4tNvk ...