HDU4292(KB11-H 最大流)
Food
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5945 Accepted Submission(s): 2010
Problem Description
The issue comes up as people in your college are more and more difficult to serve with meal: They eat only some certain kinds of food and drink, and with requirement unsatisfied, go away directly.
You have prepared F (1 <= F <= 200) kinds of food and D (1 <= D <= 200) kinds of drink. Each kind of food or drink has certain amount, that is, how many people could this food or drink serve. Besides, You know there’re N (1 <= N <= 200) people and you too can tell people’s personal preference for food and drink.
Back to your goal: to serve as many people as possible. So you must decide a plan where some people are served while requirements of the rest of them are unmet. You should notice that, when one’s requirement is unmet, he/she would just go away, refusing any service.
Input
For each test case, the first line contains three numbers: N,F,D, denoting the number of people, food, and drink.
The second line contains F integers, the ith number of which denotes amount of representative food.
The third line contains D integers, the ith number of which denotes amount of representative drink.
Following is N line, each consisting of a string of length F. e jth character in the ith one of these lines denotes whether people i would accept food j. “Y” for yes and “N” for no.
Following is N line, each consisting of a string of length D. e jth character in the ith one of these lines denotes whether people i would accept drink j. “Y” for yes and “N” for no.
Please process until EOF (End Of File).
Output
Sample Input
1 1 1
1 1 1
YYN
NYY
YNY
YNY
YNY
YYN
YYN
NNY
Sample Output
Source
- //2017-08-24
- #include <cstdio>
- #include <cstring>
- #include <iostream>
- #include <algorithm>
- #include <queue>
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- 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 main()
- {
- //std::ios::sync_with_stdio(false);
- //freopen("inputH.txt", "r", stdin);
- int n, f, d, w;
- while(scanf("%d%d%d", &n, &f, &d) != EOF){
- int s = , t = *n+f+d+;
- dinic.init(s, t);
- for(int i = ; i <= n; i++)
- add_edge(i, n+i, );
- for(int i = ; i <= f; i++){
- scanf("%d", &w);
- add_edge(s, *n+i, w);
- }
- for(int i = ; i <= d; i++){
- scanf("%d", &w);
- add_edge(*n+f+i, t, w);
- }
- for(int i = ; i <= n; i++){
- scanf("%s", str);
- for(int j = ; j < f; j++){
- if(str[j] == 'Y')
- add_edge(*n+j+, i, );
- }
- }
- for(int i = ; i <= n; i++){
- scanf("%s", str);
- for(int j = ; j < d; j++){
- if(str[j] == 'Y')
- add_edge(n+i, *n+f+j+, );
- }
- }
- printf("%d\n", dinic.maxflow());
- }
- return ;
- }
HDU4292(KB11-H 最大流)的更多相关文章
- (转载)H.264码流的RTP封包说明
H.264的NALU,RTP封包说明(转自牛人) 2010-06-30 16:28 H.264 RTP payload 格式 H.264 视频 RTP 负载格式 1. 网络抽象层单元类型 (NALU) ...
- 获得H.264视频分辨率的方法
转自:http://www.cnblogs.com/likwo/p/3531241.html 在使用ffmpeg解码播放TS流的时候(例如之前写过的UDP组播流),在连接时往往需要耗费大量时间.经过d ...
- IOS 瀑布流UICollectionView实现
IOS 瀑布流UICollectionView实现 在实现瀑布流之前先来看看瀑布流的雏形(此方法的雏形 UICollectionView) 对于UICollectionView我们有几点注意事项 它和 ...
- H.264 基础及 RTP 封包详解
转自:http://my.oschina.net/u/1431835/blog/393315 一. h264基础概念 1.NAL.Slice与frame意思及相互关系 1 frame的数据可以分为多个 ...
- 【iOS开发】collectionView 瀑布流实现
一.效果展示 二.思路分析 1> 布局的基本流程 当设置好collectionView的布局方式之后(UICollectionViewFlowLayout),当系统开始布局的时候,会调用 pre ...
- H.264 RTP 封包格式
H.264 视频 RTP 负载格式 1. 网络抽象层单元类型 (NALU) NALU 头由一个字节组成, 它的语法如下: +---------------+ |0|1|2|3|4|5|6|7 ...
- H.264 RTPpayload 格式------ H.264 视频 RTP 负载格式
H.264 RTPpayload 格式------ H.264 视频 RTP 负载格式 1. 网络抽象层单元类型 (NALU) NALU 头由一个字节组成, 它的语法如下: +------------ ...
- H.264格式,iOS硬编解码 以及 iOS 11对HEVC硬编解码的支持
H.264格式,iOS硬编解码 以及 iOS 11对HEVC硬编解码的支持 1,H.264格式 网络表示层NAL,如图H.264流由一帧一帧的NALU组成: SPS:序列参数集,作用于一系列连续的编码 ...
- H.264流媒体协议格式中的Annex B格式和AVCC格式深度解析
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Romantic_Energy/article/details/50508332本文需要读者对H.26 ...
- H.264 RTP PAYLOAD 格式
H.264 视频 RTP 负载格式 1. 网络抽象层单元类型 (NALU) NALU 头由一个字节组成, 它的语法如下: +---------------+ |0|1|2|3|4|5|6|7 ...
随机推荐
- cad.net之ACAD和GCAD环境变量获取
#if AC2006 || AC2007 || AC2008 || AC2009 || AC2010 || AC2011 || AC2012 [System.Security.SuppressUnma ...
- 杀掉所有 skynet 进程
ps aux | grep skynet | awk '/config/{print $2}' | xargs kill
- javaweb项目中的过滤器的使用
翻阅博客园的的时候,看到两篇关于javaweb过滤器的帖子写的很好,这里备忘一下: 过滤器基础:http://www.cnblogs.com/xdp-gacl/p/3948353.html 获取器案例 ...
- 一步步Cobol 400上手自学入门教程05 - 表
在COBOL中有几类典型结构的表.这几类典型结构的表在大体上可分为下标表和索引表两大类.另外,根据表的重复次数定义又有定长表和变长表.此外,表还允许嵌套,因此还有嵌套表.这几类表均符合表的基本定义,都 ...
- maven封装jar包遇到的问题
使用eclipse编译后可以生成jar包,使用mvn clean package指令打包报错,错误如下:No compiler is provided in this environment. Per ...
- odoo开发笔记--工作流
虽然odoo10里边取消了工作流 Odoo Workflow http://www.jeffzhang.cn/Odoo-Workflow-Notes/
- 性能优化中CPU、内存、磁盘IO、网络性能的依赖(转)
关于系统性能优化,推荐一篇不错的博客! 系统优化是一项复杂.繁琐.长期的工作,优化前需要监测.采集.测试.评估,优化后也需要测试.采集.评估.监测,而且是一个长期和持续的过程,不 是说现在优化了,测试 ...
- 【原创】Your Connection is not private
用Chrome打开google等https网站时碰到问题: “your connection is not private”. 后来发现是跟GoAgent的安全证书有关系(我用XX.NETFQ) 解决 ...
- 字符串编码C#
给定一个字符串,请你将字符串重新编码,将连续的字符替换成“连续出现的个数+字符”.比如字符串AAAABCCDAA会被编码成4A1B2C1D2A. 输入描述: 每个测试输入包含1个测试用例 每个测试用例 ...
- IdentityServer-Protecting an API using Client Credentials
使用客户凭证保护API 这篇快速开始将展示使用IdentityServer保护APIs的最基本使用场景. 在此场景中我们将定义一个API和一个要访问此API的客户端. 客户端将向IdentitySer ...