Escape

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 13028    Accepted Submission(s): 3264

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
 
Output
Determine whether all people can live up to these stars
If you can output YES, otherwise output NO.
 
Sample Input
1 1
1
1

2 2
1 0
1 0
1 1

 
Sample Output
YES
NO
 
Source
 

  裸?毕竟是多校的题,能裸吗。。。有点bishu。。

  看到n和m的范围相差这么大,没点想法吗

  把选择相同的人缩为一个点,顺便统计个数,就是裸了,

  注意用c++交。。。。

  

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define pd(a) printf("%d\n", a);
#define plld(a) printf("%lld\n", a);
#define pc(a) printf("%c\n", a);
#define ps(a) printf("%s\n", a);
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 1e6 + , INF = 0x7fffffff, LL_INF = 0x7fffffffffffffff;
int n, m, s, t, cnt;
int head[maxn], d[maxn], cur[maxn];
map<string, int> se;
vector<string> g;
string str;
struct node
{
int u, v, c, next;
}Node[maxn]; void add_(int u, int v, int c)
{
Node[cnt].u = u;
Node[cnt].v = v;
Node[cnt].c = c;
Node[cnt].next = head[u];
head[u] = cnt++;
} void add(int u, int v, int c)
{
add_(u, v, c);
add_(v, u, );
} bool bfs()
{
queue<int> Q;
mem(d, );
Q.push(s);
d[s] = ;
while(!Q.empty())
{
int u = Q.front(); Q.pop();
for(int i = head[u]; i != -; i = Node[i].next)
{
node e = Node[i];
if(!d[e.v] && e.c > )
{
d[e.v] = d[u] + ;
Q.push(e.v);
if(e.v == t) return ;
}
}
}
return d[t] != ;
} int dfs(int u, int cap)
{
int ret = ;
if(u == t || cap == )
return cap;
for(int &i = cur[u]; i != -; i = Node[i].next)
{
node e = Node[i];
if(d[e.v] == d[u] + && e.c > )
{
int V = dfs(e.v, min(e.c, cap));
Node[i].c -= V;
Node[i ^ ].c += V;
ret += V;
cap -= V;
if(cap == ) break;
}
}
if(cap > ) d[u] = -;
return ret;
} int Dinic()
{
int ret = ;
while(bfs())
{
memcpy(cur, head, sizeof(head));
ret += dfs(s, INF);
}
return ret;
} void init()
{
mem(head, -);
se.clear();
g.clear();
cnt = ;
} int main()
{
while(~scanf("%d%d", &n, &m))
{
getchar();
init();
int ans = ;
rap(i, , n)
{
getline(cin, str);
if(!se[str])
{
++ans;
g.push_back(str);
int len = str.size();
for(int j = ; j < len; j++)
{
if(str[j] == '')
add( + ans, (j + ) / , INF);
}
}
se[str]++;
}
s = , t = + ans + ;
int max_flow = ;
for(int i = ; i < g.size(); i++)
{
add(s, + i + , se[g[i]]);
max_flow += se[g[i]];
}
int tmp;
for(int i = ; i <= m; i++)
{
rd(tmp);
add(i, t, tmp);
}
if(max_flow == Dinic())
{
printf("YES\n");
}
else
printf("NO\n"); } return ;
}

Escape HDU - 3605(归类建边)的更多相关文章

  1. 网络流 E - Escape HDU - 3605

    2012 If this is the end of the world how to do? I do not know how. But now scientists have found tha ...

  2. M - Escape - HDU 3605 - (缩点+最大流SAP)

    题目大意:2012世界末日来了,科学家发现了一些星球可以转移人口,不过有的人可以在一些星球上生存有的人不行,而且每个星球都有一定的承载量,现在想知道是否所有的人都可以安全转移呢? 输入:首先输入一个N ...

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

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

  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 3605 Escape (最大流 + 缩点)

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

  6. HDU 3605 Escape 最大流+状压

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

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

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

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

    http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意: 有n个人和m个星球,每个人可以去某些星球和不可以去某些星球,并且每个星球有最大居住人数,判断是否所 ...

  9. hdu 3605 Escape 二分图的多重匹配(匈牙利算法)

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

随机推荐

  1. mysqldump 和mysqlbinlog

    一.mysqldump 1.备份test库 #mysqldump -uroot -p' test >test.sql 2.备份 -B参数 ' -B test >test_B.sql --B ...

  2. Yii1.1框架实现PHP极光推送消息通知

    一.下载极光推送PHP SDK,解压后放在/protected/components/目录下,如下图所示: 二.完善修改下官方的demo例子,我这里复制一份demo,改为NotifyPush.php, ...

  3. CNZZ友盟访问明细的采集办法

    www.cnzz.com是中文网站统计分析平台,很多站长需要获取网站提供的访问明细,以做分析. 直接采集这个网站的数据相当麻烦,通过浏览器或者fiddlercore就简单多了. 2.0新版,通过浏览器 ...

  4. debian中完全删除mysql

    参考自:http://www.jb51.net/article/50884.htm 之前实验室的人说找不到完全删除已安装的mysql-cluster的方法,我当时没在意,今天不得不删除他之前安装的my ...

  5. PHPer未来路在何方...

    PHP 从诞生到现在已经有20多年历史,从Web时代兴起到移动互联网退潮,互联网领域各种编程语言和技术层出不穷, Node.js . GO . Python 不断地在挑战 PHP 的地位.这些技术的推 ...

  6. # 【Python3练习题 007】 有一对兔子,从出生后第3个月起每个月都生一对兔子, # 小兔子长到第三个月后每个月又生一对兔子, # 假如兔子都不死,问每个月的兔子总数为多少?

    # 有一对兔子,从出生后第3个月起每个月都生一对兔子,# 小兔子长到第三个月后每个月又生一对兔子, # 假如兔子都不死,问每个月的兔子总数为多少?这题反正我自己是算不出来.网上说是经典的“斐波纳契数列 ...

  7. maven用框架编写网页运行出现HTTP Status 500 - Unable to compile class for JSP

    利用maven整合框架的时候,通过浏览器访问时,如果出现  HTTP 500-Unable to compile class for JSP 的错误,应该怎么解决呢? 之前在网上看了好多人的解决方案. ...

  8. java的static与C#的static的异同

    static static同样可以用在类.方法.变量上面,但是在java和C#中所表示的意思完全不同,我个人的总结是C#中的静态和非静态是有一个明显的分界的,静态的是属于类级别的,而非静态的是属于实例 ...

  9. 使用docker化的nginx 反向代理 docker化的GSCloud 的方法

    1. 首先将nginx 的image pull 下来. docker pull nginx 2. 将最近的可用的 参数文件 复制过来当一个目录 mkdir /nginx ssh root@linuxs ...

  10. easyUI 数据表格datagrid的使用

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...