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

  You, a part-time dining service worker in your college’s dining hall, are now confused with a new problem: serve as many people as possible.
  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

  There are several test cases.
  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

  For each test case, please print a single line with one integer, the maximum number of people to be satisfied.
 

Sample Input

4 3 3
1 1 1
1 1 1
YYN
NYY
YNY
YNY
YNY
YYN
YYN
NNY
 

Sample Output

3
 

Source

 
建图与POJ3281一毛一样,边开少了狂T。。。
  1. //2017-08-24
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <queue>
  7. #pragma comment(linker, "/STACK:1024000000,1024000000")
  8.  
  9. using namespace std;
  10.  
  11. const int N = ;
  12. const int M = ;
  13. const int INF = 0x3f3f3f3f;
  14. int head[N], tot;
  15. struct Edge{
  16. int next, to, w;
  17. }edge[M];
  18.  
  19. void add_edge(int u, int v, int w){
  20. edge[tot].w = w;
  21. edge[tot].to = v;
  22. edge[tot].next = head[u];
  23. head[u] = tot++;
  24.  
  25. edge[tot].w = ;
  26. edge[tot].to = u;
  27. edge[tot].next = head[v];
  28. head[v] = tot++;
  29. }
  30.  
  31. struct Dinic{
  32. int level[N], S, T;
  33. void init(int _S, int _T){
  34. S = _S;
  35. T = _T;
  36. tot = ;
  37. memset(head, -, sizeof(head));
  38. }
  39. bool bfs(){
  40. queue<int> que;
  41. memset(level, -, sizeof(level));
  42. level[S] = ;
  43. que.push(S);
  44. while(!que.empty()){
  45. int u = que.front();
  46. que.pop();
  47. for(int i = head[u]; i != -; i = edge[i].next){
  48. int v = edge[i].to;
  49. int w = edge[i].w;
  50. if(level[v] == - && w > ){
  51. level[v] = level[u]+;
  52. que.push(v);
  53. }
  54. }
  55. }
  56. return level[T] != -;
  57. }
  58. int dfs(int u, int flow){
  59. if(u == T)return flow;
  60. int ans = , fw;
  61. for(int i = head[u]; i != -; i = edge[i].next){
  62. int v = edge[i].to, w = edge[i].w;
  63. if(!w || level[v] != level[u]+)
  64. continue;
  65. fw = dfs(v, min(flow-ans, w));
  66. ans += fw;
  67. edge[i].w -= fw;
  68. edge[i^].w += fw;
  69. if(ans == flow)return ans;
  70. }
  71. if(ans == )level[u] = -;
  72. return ans;
  73. }
  74. int maxflow(){
  75. int flow = , f;
  76. while(bfs())
  77. while((f = dfs(S, INF)) > )
  78. flow += f;
  79. return flow;
  80. }
  81. }dinic;
  82.  
  83. char str[N];
  84.  
  85. int main()
  86. {
  87. //std::ios::sync_with_stdio(false);
  88. //freopen("inputH.txt", "r", stdin);
  89. int n, f, d, w;
  90. while(scanf("%d%d%d", &n, &f, &d) != EOF){
  91. int s = , t = *n+f+d+;
  92. dinic.init(s, t);
  93. for(int i = ; i <= n; i++)
  94. add_edge(i, n+i, );
  95. for(int i = ; i <= f; i++){
  96. scanf("%d", &w);
  97. add_edge(s, *n+i, w);
  98. }
  99. for(int i = ; i <= d; i++){
  100. scanf("%d", &w);
  101. add_edge(*n+f+i, t, w);
  102. }
  103. for(int i = ; i <= n; i++){
  104. scanf("%s", str);
  105. for(int j = ; j < f; j++){
  106. if(str[j] == 'Y')
  107. add_edge(*n+j+, i, );
  108. }
  109. }
  110. for(int i = ; i <= n; i++){
  111. scanf("%s", str);
  112. for(int j = ; j < d; j++){
  113. if(str[j] == 'Y')
  114. add_edge(n+i, *n+f+j+, );
  115. }
  116. }
  117. printf("%d\n", dinic.maxflow());
  118. }
  119. return ;
  120. }

HDU4292(KB11-H 最大流)的更多相关文章

  1. (转载)H.264码流的RTP封包说明

    H.264的NALU,RTP封包说明(转自牛人) 2010-06-30 16:28 H.264 RTP payload 格式 H.264 视频 RTP 负载格式 1. 网络抽象层单元类型 (NALU) ...

  2. 获得H.264视频分辨率的方法

    转自:http://www.cnblogs.com/likwo/p/3531241.html 在使用ffmpeg解码播放TS流的时候(例如之前写过的UDP组播流),在连接时往往需要耗费大量时间.经过d ...

  3. IOS 瀑布流UICollectionView实现

    IOS 瀑布流UICollectionView实现 在实现瀑布流之前先来看看瀑布流的雏形(此方法的雏形 UICollectionView) 对于UICollectionView我们有几点注意事项 它和 ...

  4. H.264 基础及 RTP 封包详解

    转自:http://my.oschina.net/u/1431835/blog/393315 一. h264基础概念 1.NAL.Slice与frame意思及相互关系 1 frame的数据可以分为多个 ...

  5. 【iOS开发】collectionView 瀑布流实现

    一.效果展示 二.思路分析 1> 布局的基本流程 当设置好collectionView的布局方式之后(UICollectionViewFlowLayout),当系统开始布局的时候,会调用 pre ...

  6. H.264 RTP 封包格式

    H.264 视频 RTP 负载格式 1. 网络抽象层单元类型 (NALU) NALU 头由一个字节组成, 它的语法如下: +---------------+      |0|1|2|3|4|5|6|7 ...

  7. H.264 RTPpayload 格式------ H.264 视频 RTP 负载格式

    H.264 RTPpayload 格式------ H.264 视频 RTP 负载格式 1. 网络抽象层单元类型 (NALU) NALU 头由一个字节组成, 它的语法如下: +------------ ...

  8. H.264格式,iOS硬编解码 以及 iOS 11对HEVC硬编解码的支持

    H.264格式,iOS硬编解码 以及 iOS 11对HEVC硬编解码的支持 1,H.264格式 网络表示层NAL,如图H.264流由一帧一帧的NALU组成: SPS:序列参数集,作用于一系列连续的编码 ...

  9. H.264流媒体协议格式中的Annex B格式和AVCC格式深度解析

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Romantic_Energy/article/details/50508332本文需要读者对H.26 ...

  10. H.264 RTP PAYLOAD 格式

    H.264 视频 RTP 负载格式 1. 网络抽象层单元类型 (NALU) NALU 头由一个字节组成, 它的语法如下: +---------------+      |0|1|2|3|4|5|6|7 ...

随机推荐

  1. cad.net之ACAD和GCAD环境变量获取

    #if AC2006 || AC2007 || AC2008 || AC2009 || AC2010 || AC2011 || AC2012 [System.Security.SuppressUnma ...

  2. 杀掉所有 skynet 进程

    ps aux | grep skynet | awk '/config/{print $2}' | xargs kill

  3. javaweb项目中的过滤器的使用

    翻阅博客园的的时候,看到两篇关于javaweb过滤器的帖子写的很好,这里备忘一下: 过滤器基础:http://www.cnblogs.com/xdp-gacl/p/3948353.html 获取器案例 ...

  4. 一步步Cobol 400上手自学入门教程05 - 表

    在COBOL中有几类典型结构的表.这几类典型结构的表在大体上可分为下标表和索引表两大类.另外,根据表的重复次数定义又有定长表和变长表.此外,表还允许嵌套,因此还有嵌套表.这几类表均符合表的基本定义,都 ...

  5. maven封装jar包遇到的问题

    使用eclipse编译后可以生成jar包,使用mvn clean package指令打包报错,错误如下:No compiler is provided in this environment. Per ...

  6. odoo开发笔记--工作流

    虽然odoo10里边取消了工作流 Odoo Workflow http://www.jeffzhang.cn/Odoo-Workflow-Notes/

  7. 性能优化中CPU、内存、磁盘IO、网络性能的依赖(转)

    关于系统性能优化,推荐一篇不错的博客! 系统优化是一项复杂.繁琐.长期的工作,优化前需要监测.采集.测试.评估,优化后也需要测试.采集.评估.监测,而且是一个长期和持续的过程,不 是说现在优化了,测试 ...

  8. 【原创】Your Connection is not private

    用Chrome打开google等https网站时碰到问题: “your connection is not private”. 后来发现是跟GoAgent的安全证书有关系(我用XX.NETFQ) 解决 ...

  9. 字符串编码C#

    给定一个字符串,请你将字符串重新编码,将连续的字符替换成“连续出现的个数+字符”.比如字符串AAAABCCDAA会被编码成4A1B2C1D2A. 输入描述: 每个测试输入包含1个测试用例 每个测试用例 ...

  10. IdentityServer-Protecting an API using Client Credentials

    使用客户凭证保护API 这篇快速开始将展示使用IdentityServer保护APIs的最基本使用场景. 在此场景中我们将定义一个API和一个要访问此API的客户端. 客户端将向IdentitySer ...