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],也有可能不出现卡 ...
随机推荐
- jzoj3086 [分層圖最短路]
分層圖最短路即可 #include<bits/stdc++.h> using namespace std; #define N 1000010 int n,m,v[N*2],nxt[N*2 ...
- Java并发编程总结3——AQS、ReentrantLock、ReentrantReadWriteLock
本文内容主要总结自<Java并发编程的艺术>第5章——Java中的锁. 一.AQS AbstractQueuedSynchronizer(简称AQS),队列同步器,是用来构建锁或者其他同步 ...
- Vue + Bootstrap 制作炫酷个人简历(一)
最近看了别人做的简历,简单炫酷,自己非常喜欢,于是打算自己做一个,尝试一下. 由于写这篇随笔的时候才开始动工,所以目前没有成品给大家看. emmm等我更新完会在最后附上成品. 现在 开始! 首先 配置 ...
- 关于Java抽象类,接口与实现接口及派生类继承基类
1. 抽象类 抽象类就是有一个或多个方法只被声明而未被实现. 抽象方法的声明以分号结束,并且用关键字abstract来说明它以标识它为抽象方法. 格式: public abstract class 类 ...
- JavaScript getter和setter
对象的属性是由属性名name,值key,和其他特性(可读写性 writable,可枚举性enumerable,可配置性configurable)组成的.从ES5开发,提供了getter和setter ...
- Ubutntu安装docker启动报Removed /etc/systemd/system/docker.service.
Ubutntu安装docker启动报Removed /etc/systemd/system/docker.service.的错误,只需要执行以下三条命令. systemctl unmask docke ...
- Android众说纷纭分辨率
Andoid最被人诟病的就是显示屏的各种不同尺寸和不同分辨率.由于Android厂商的纷繁多样,导致出现了不同尺寸和不同分辨率的手机,指示开发者需要兼容各种手机屏幕.本文想学习的就是Android的显 ...
- let'encript 解决证书问题
今天服务器let'encript证书过期了,年纪大了老忘,不得不把别人的博客看一遍,就是因为我不想定时任务执行acme_tiny.py,还是写个文档记下,很久不写对外博客了,冒个泡. 1.创建普通域名 ...
- Element ui级联地址省市区插件
安装 npm install element-china-area-data -S 使用 import { provinceAndCityData, regionData, provinceAndCi ...
- Python学习--23 内建模块及第三方库
本文将介绍python里常用的模块.如未特殊说明,所有示例均以python3.4为例: $ python -V Python 3.4.3 网络请求 urllib urllib提供了一系列用于操作URL ...