HDU 3605 Escape 最大流
来源:互联网 发布:2017色情软件app 编辑:程序博客网 时间:2024/04/29 14:30
Escape
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 7831 Accepted Submission(s): 1702
Problem Description
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.
Input
More set of test data, the beginning of each data is n (1 <= n <= 100000), m (1 <= m <= 10) n indicate there n people on the earth, m representatives m planet, planet and people labels are from 0. Here are n lines, each line represents a suitable living conditions of people, each row has m digits, the ith digits is 1, said that a person is fit to live in the ith-planet, or is 0 for this person is not suitable for living in the ith planet.
The last line has m digits, the ith digit ai indicates the ith planet can contain ai people most..
0 <= ai <= 100000
The last line has m digits, the ith digit ai indicates the ith planet can contain ai people most..
0 <= ai <= 100000
Output
Determine whether all people can live up to these stars
If you can output YES, otherwise output NO.
If you can output YES, otherwise output NO.
Sample Input
1 1112 21 01 01 1
Sample Output
YESNO
//二进制压缩加dinic//因为最多十个星球,所有人的状态可以分为2的10次方种,即1024种。统计相同状态人的个数,然后建图#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>#include <cmath>#include <queue>#include <vector>using namespace std;const int N = 1500;const int INF = 0x3f3f3f3f;struct edge{ int to, cap, rev;};vector <edge> G[N];int level[N], iter[N];void add_edge(int from, int to, int cap){ edge e; e.to = to, e.cap = cap, e.rev = G[to].size(); G[from].push_back(e); e.to = from, e.cap = 0, e.rev = G[from].size() - 1; G[to].push_back(e);}void bfs(int s){ memset(level, -1, sizeof level); queue <int> que; level[s] = 0; que.push(s); while(! que.empty()) { int v = que.front(); que.pop(); for(int i = 0; i < G[v].size(); i++) { edge &e = G[v][i]; if(e.cap > 0 && level[e.to] < 0) { level[e.to] = level[v] + 1; que.push(e.to); } } }}int dfs(int v, int t, int f){ if(v == t) return f; for(int &i = iter[v]; i < G[v].size(); i++) { edge &e = G[v][i]; if(e.cap > 0 && level[v] < level[e.to]) { int d = dfs(e.to, t, min(f, e.cap)); if(d > 0) { e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0;}int max_flow(int s, int t){ int flow = 0, f; while(true) { bfs(s); if(level[t] < 0) return flow; memset(iter, 0, sizeof iter); while(f = dfs(s, t, INF), f > 0) flow += f; }}int main(){ int n, m, a; int cnt[1500]; while(~ scanf("%d%d", &n, &m)) { memset(cnt, 0, sizeof cnt); int max1 = -1; for(int i = 0; i < n; i++) { int tmp = 0; for(int i = 0; i < m; i++) { scanf("%d", &a); tmp = tmp * 2 + a; } max1 = max(max1, tmp); cnt[tmp]++; //二进制压缩,统计人数 } for(int i = 0; i <= max1; i++) { if(cnt[i] == 0) continue; add_edge(0, i, cnt[i]); //把0作为超级源点,压缩状态为0时不会连接,所以不必担心和超级源点冲突 } int b = max1 + 1; //b为第一个星球 for(int i = 0; i <= max1; i++) { if(cnt[i] == 0) continue; int k = 0; for(int j = m-1; j >= 0; j--) { if( ((i >> j) & 1) == 1) add_edge(i, b + k, cnt[i]); k++; } } for(int i = 0; i < m; i++) { scanf("%d", &a); add_edge(b + i, b + m, a); //b+m为超级汇点,连接星球和超级汇点 } if(max_flow(0, b + m) >= n) printf("YES\n"); else printf("NO\n"); for(int i = 0; i <= b+m; i++) G[i].clear(); } return 0;}
0 0
- HDU 3605 Escape 最大流
- HDU 3605 Escape 最大流
- HDU 3605 Escape【最大流】
- HDU 3605 Escape 最大流
- 最大流-HDU-3605-Escape
- HDU 3605 Escape 最大流,状压
- HDU 3605 Escape(最大流+状态压缩)
- hdu 3605 Escape 状态压缩+最大流
- HDU 3605 Escape(最大流+状态压缩)
- HDU-3605-Escape(最大流+状压)
- HDU 3605 Escape(最大流+状态压缩)
- hdu 3605 Escape (最大流+状态压缩)
- HDU 3605 Escape 网络流最大流 合并点
- hdu 3605 Escape【图论-网络流-最大流-状态压缩】
- hdu 3605 Escape 多重匹配模板 (Hungary ) | 最大流
- HDU 3605 Escape(最大流+合并相同点)
- HDU -- 3605 Escape(最大流 状态合并判满流)
- HDU 3605 —— Escape 状态压缩+最大流
- 关于句柄和二级指针
- apache如何配置默认的根目录
- C#开发模式
- 第一次敲hdu蟠桃树和第二次的区别
- 我奋斗十八年不是为了和你一起喝咖啡!
- HDU 3605 Escape 最大流
- OpenSSL文档的划分
- Javascript的方法参数是不介意传递多少个参数的!
- VS2013中,为MFC程序创建属性表单
- leetcode-Path Sum II
- 朱冠胤:百度大规模数据处理架构之“不平凡之路”
- SwipeRefreshLayout + RecyclerView 实现 上拉刷新 和 下拉刷新
- 标识符命名原则——匈牙利命名法
- Ubuntu下安装AS unable to run mksdcard sdk tool.