HDU-3605-Escape(最大流, 状态压缩)
链接:
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(最大流, 状态压缩)的更多相关文章
- Hdu 3605 Escape (最大流 + 缩点)
题目链接: Hdu 3605 Escape 题目描述: 有n个人要迁移到m个星球,每个星球有最大容量,每个人有喜欢的星球,问是否所有的人都能迁移成功? 解题思路: 正常情况下建图,不会爆内存,但是T ...
- HDU 3605 Escape 最大流+状压
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 3605 Escape 最大流
题意: 如果这是2012年世界末日怎么办?我不知道该怎么做.但是现在科学家们已经发现,有些星球上的人可以生存,但有些人却不适合居住.现在科学家们需要你的帮助,就是确定所有人都能在这些行星上生活.输入多 ...
- HDU 3605 Escape (网络流,最大流,位运算压缩)
HDU 3605 Escape (网络流,最大流,位运算压缩) Description 2012 If this is the end of the world how to do? I do not ...
- hdu 5025 Saving Tang Monk 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...
- HDU 3605:Escape(最大流+状态压缩)
http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...
- HDU 3605 Escape(状压+最大流)
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Sub ...
- hdu3605(最大流+状态压缩)
传送门:Escape 题意:给出每个人适合住的星球信息和该星球能住多少人 ,第一行给出n m 代表有 n 个人 m 个星球,然后接下来n行每行m个数字 1代表适合第 i 个星球 0 代表不适合第 i ...
- HDU 1885 Key Task (BFS + 状态压缩)
题意:给定一个n*m的矩阵,里面有门,有钥匙,有出口,问你逃出去的最短路径是多少. 析:这很明显是一个BFS,但是,里面又有其他的东西,所以我们考虑状态压缩,定义三维BFS,最后一维表示拿到钥匙的状态 ...
- HDU 3681 Prison Break(状态压缩dp + BFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 前些天花时间看到的题目,但写出不来,弱弱的放弃了.没想到现在学弟居然写出这种代码来,大吃一惊附加 ...
随机推荐
- springmvc 使用Jackson框架的配置
<!--start:使用Jackson 1.x的配置,需要导入的jar包:jackson-core-lpgl-xxx.jar.jackson-mapper-lgpl-xxx.jar --> ...
- SQL注入(bool型)
sqli-labs 靶场https://blog.csdn.net/qq_41420747/article/details/81836327 教程+靶场 1. https://blog.csdn.ne ...
- AGC035 B - Even Degrees【思维·树形结构的妙用】
题目传送门 一句话题意: 首先,每一条边会产生1个入度,1个出度,因此,如果边的数量是奇数的话,图的所有节点的总出度就是奇数,不可能每个节点的出度都是偶数,因此无解. 有解时,我们先找出原图中的一棵生 ...
- 【VS开发】【图像处理】ISP图像传感器处理器基础
1 前言 做为拍照手机的核心模块之一,camera sensor效果的调整,涉及到众多的参数,如果对基本的光学原理及sensor软/硬件对图像处理的原理能有深入的理解和把握的话,对我们的 ...
- ASM下添加磁盘
linux下asm磁盘扩容,此次扩容添加4块480G磁盘 第一步:multipath -ll : 查看多路径映射磁盘(两节点都做) 配置 /etc/multipath.conf文件,配置新加磁盘的al ...
- Kettle的Kitchen和Span
Kitchen——工作(job)执行器 (命令行方式) -rep : Repository name 任务包所在存储名 -user : Repository username 执行人 ...
- Element el-table-column组件列宽度设置百分比无效
问题 使用Element table组件时,给列设置百分比宽度无效(width="30%") 解决 用属性min-width="3"代替属性width=&quo ...
- SpringBoot_02通用mapper
注意:一旦引入了通用Mapper的启动器,会覆盖Mybatis官方启动器的功能,因此需要移除对官方Mybatis启动器的依赖. 无需任何配置就可以使用了.如果有特殊需要,可以到通用mapper官网查看 ...
- java实现整数计算器
计算器代码 package stack; import java.util.ArrayList; import java.util.List; import java.util.Scanner; im ...
- 前端技术之:如何Mock GraphQL接口数据
// 第一步:引入所依赖的库const { makeExecutableSchema, addMockFunctionsToSchema } = require('graphql-tools');co ...