HDU3605(KB11-M 状态压缩+最大流)
Escape
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 10920 Accepted Submission(s): 2630
Problem Description
Input
The last line has m digits, the ith digit ai indicates the ith planet can contain ai people most..
0 <= ai <= 100000
Output
If you can output YES, otherwise output NO.
Sample Input
1
1
2 2
1 0
1 0
1 1
Sample Output
NO
Source
//2017-08-24
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue> using namespace std; const int N = ;
const int M = ;
const int INF = 0x3f3f3f3f;
int head[N], tot;
struct Edge{
int next, to, w;
}edge[M]; void add_edge(int u, int v, int w){
edge[tot].w = w;
edge[tot].to = v;
edge[tot].next = head[u];
head[u] = tot++; edge[tot].w = ;
edge[tot].to = u;
edge[tot].next = head[v];
head[v] = tot++;
} struct Dinic{
int level[N], S, T;
void init(int _S, int _T){
S = _S;
T = _T;
tot = ;
memset(head, -, sizeof(head));
}
bool bfs(){
queue<int> que;
memset(level, -, sizeof(level));
level[S] = ;
que.push(S);
while(!que.empty()){
int u = que.front();
que.pop();
for(int i = head[u]; i != -; i = edge[i].next){
int v = edge[i].to;
int w = edge[i].w;
if(level[v] == - && w > ){
level[v] = level[u]+;
que.push(v);
}
}
}
return level[T] != -;
}
int dfs(int u, int flow){
if(u == T)return flow;
int ans = , fw;
for(int i = head[u]; i != -; i = edge[i].next){
int v = edge[i].to, w = edge[i].w;
if(!w || level[v] != level[u]+)
continue;
fw = dfs(v, min(flow-ans, w));
ans += fw;
edge[i].w -= fw;
edge[i^].w += fw;
if(ans == flow)return ans;
}
if(ans == )level[u] = -;
return ans;
}
int maxflow(){
int flow = , f;
while(bfs())
while((f = dfs(S, INF)) > )
flow += f;
return flow;
}
}dinic; char str[N];
int status[<<];//status[S]表示状态为S的人数,例如S=1010,表示可以在2号和4号星球上生存(从低位标号) int main()
{
std::ios::sync_with_stdio(false);
//freopen("inputM.txt", "r", stdin);
int n, m;
while(cin>>n>>m){
int s = , t = n+m+;
dinic.init(s, t);
int w;
memset(status, , sizeof(status));
for(int i = ; i <= n; i++){
int tmp = ;
for(int j = ; j <= m; j++){
tmp <<= ;
cin>>w;
tmp |= w;
}
status[tmp]++;
}
for(int i = ; i <= (<<); i++){
if(status[i]){
add_edge(s, i, status[i]);
for(int j = ; j <= m; j++){
if(i & (<<(j-)))
add_edge(i, n+j, status[i]);
}
}
}
int sum = ;
for(int i = ; i <= m; i++){
cin>>w;
sum += w;
add_edge(n+i, t, w);
}
if(sum < n){
cout<<"NO"<<endl;
continue;
}
if(dinic.maxflow() == n)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return ;
}
HDU3605(KB11-M 状态压缩+最大流)的更多相关文章
- Escape(状态压缩+最大流,好题)
Escape http://acm.hdu.edu.cn/showproblem.php?pid=3605 Time Limit: 4000/2000 MS (Java/Others) Memo ...
- HDU3605:Escape(状态压缩+最大流)
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- HDU 3605 Escape(状态压缩+最大流)
http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意: 有n个人和m个星球,每个人可以去某些星球和不可以去某些星球,并且每个星球有最大居住人数,判断是否所 ...
- Codeforces 1383F - Special Edges(状态压缩+最大流)
Codeforces 题目传送门 & 洛谷题目传送门 首先暴力显然是不行的,如果你暴力最大流过了我请你吃糖 注意到本题的 \(k\) 很小,考虑以此为突破口解题.根据最大流等于最小割定理,点 ...
- hdu3605(最大流+状态压缩)
传送门:Escape 题意:给出每个人适合住的星球信息和该星球能住多少人 ,第一行给出n m 代表有 n 个人 m 个星球,然后接下来n行每行m个数字 1代表适合第 i 个星球 0 代表不适合第 i ...
- HDU 3605:Escape(最大流+状态压缩)
http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...
- hdu1565 网络流或状态压缩DP
对于网络流有一个定理: 最小点权覆盖集=最大网络流: 最大点权独立集=总权值-最小点权覆盖集: 网络流解法代码如下: #include<cstdio> #include<iostre ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- [HDU 4336] Card Collector (状态压缩概率dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...
随机推荐
- “全栈2019”Java多线程第三十三章:await与signal/signalAll
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...
- 给Ubuntu18.04安装mac os主题<转载>
给Ubuntu18.04安装mac os主题 转载来自 https://www.cnblogs.com/feipeng8848(作者) 参考文献 https://linuxhint.com/gnom ...
- Linux学习笔记-基本操作5
1. Linux文件操作相关函数 stat函数 :获取文件属性(从inode上获取) 返回值: 成功:0 ...
- C#6.0语言规范(十) 类
类是可以包含数据成员(常量和字段),函数成员(方法,属性,事件,索引器,运算符,实例构造函数,析构函数和静态构造函数)和嵌套类型的数据结构.类类型支持继承,这是一种派生类可以扩展和专门化基类的机制. ...
- 【ElasticSearch】:索引Index、文档Document、字段Field
因为从ElasticSearch6.X开始,官方准备废弃Type了.对应数据库,对ElasticSearch的理解如下: ElasticSearch 索引Index 文档Document 字段Fiel ...
- sublime text3 -- JavaScript Completions
今天在使用sublime text3时,它 智能 的自动安装了一个插件,JavaScript Completions.一般插件都是为了提高开发效率的,于是百度搜了一下用法. 相关说明很少,packag ...
- django admin编辑被外键关联的主表时支持显示字表记录
假设有模型 class A(models.Model): name = models.CharField() class B(models.Model): name = models.CharFiel ...
- socket http tcp udp ip 协议
Socket可以支持不同的传输层协议(TCP或UDP),当使用TCP协议进行连接时,该Socket连接就是一个TCP连接. socket是在应用层和传输层之间的一个抽象层,它把TCP/IP层复杂的操作 ...
- 从C#到TypeScript - 类型
总目录 从C#到TypeScript - 类型 从C#到TypeScript - 高级类型 从C#到TypeScript - 变量 从C#到TypeScript - 接口 从C#到TypeScript ...
- SpringBoot用@ConfigurationProperties获取配置文件值
SpringBoot的配置文件有yml和properties两种,看一些文章说yml以数据为中心,比较好.个人觉得properties更好用,所以这里以properties格式为例来说. 我们都知道@ ...