链接:

https://vjudge.net/problem/HDU-4292

题意:

  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.

思路:

最大流,建图,模板题.

代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <vector>
  5. //#include <memory.h>
  6. #include <queue>
  7. #include <set>
  8. #include <map>
  9. #include <algorithm>
  10. #include <math.h>
  11. #include <stack>
  12. #include <string>
  13. #pragma comment(linker, "/STACK:1024000000,1024000000")
  14. #define MINF 0x3f3f3f3f
  15. using namespace std;
  16. typedef long long LL;
  17. const int MAXN = 200+10;
  18. const int INF = 1e9;
  19. struct Edge
  20. {
  21. int from, to, cap;
  22. };
  23. vector<int> G[MAXN*4];
  24. vector<Edge> edges;
  25. int Dis[MAXN*4];
  26. int Fo, Dr;
  27. int n, f, d, s, t;
  28. void Init()
  29. {
  30. for (int i = s;i <= t;i++)
  31. G[i].clear();
  32. edges.clear();
  33. }
  34. void AddEdge(int from, int to, int cap)
  35. {
  36. edges.push_back(Edge{from, to, cap});
  37. edges.push_back(Edge{to, from, 0});
  38. G[from].push_back(edges.size()-2);
  39. G[to].push_back(edges.size()-1);
  40. }
  41. bool Bfs()
  42. {
  43. memset(Dis, -1, sizeof(Dis));
  44. queue<int> que;
  45. que.push(s);
  46. Dis[s] = 0;
  47. while (!que.empty())
  48. {
  49. int u = que.front();
  50. que.pop();
  51. for (int i = 0;i < G[u].size();i++)
  52. {
  53. Edge &e = edges[G[u][i]];
  54. if (e.cap > 0 && Dis[e.to] == -1)
  55. {
  56. Dis[e.to] = Dis[u]+1;
  57. que.push(e.to);
  58. }
  59. }
  60. }
  61. return Dis[t] != -1;
  62. }
  63. int Dfs(int u, int flow)
  64. {
  65. if (u == t)
  66. return flow;
  67. int res = 0;
  68. for (int i = 0;i < G[u].size();i++)
  69. {
  70. Edge &e = edges[G[u][i]];
  71. if (e.cap > 0 && Dis[u]+1 == Dis[e.to])
  72. {
  73. int tmp = Dfs(e.to, min(flow, e.cap));
  74. e.cap -= tmp;
  75. flow -= tmp;
  76. res += tmp;
  77. edges[G[u][i]^1].cap += tmp;
  78. if (flow == 0)
  79. break;
  80. }
  81. }
  82. if (res == 0)
  83. Dis[u] = -1;
  84. return res;
  85. }
  86. int MaxFlow()
  87. {
  88. int res = 0;
  89. while (Bfs())
  90. res += Dfs(s, INF);
  91. return res;
  92. }
  93. int main()
  94. {
  95. ios::sync_with_stdio(false);
  96. cin.tie(0);
  97. while (cin >> n >> f >> d)
  98. {
  99. s = 0, t = n*2+f+d+1;
  100. Init();
  101. for (int i = 1;i <= f;i++)
  102. {
  103. cin >> Fo;
  104. AddEdge(0, 2*n+i, Fo);
  105. }
  106. for (int i = 1;i <= d;i++)
  107. {
  108. cin >> Dr;
  109. AddEdge(2*n+f+i, t, Dr);
  110. }
  111. for (int i = 1;i <= n;i++)
  112. AddEdge(i*2-1, i*2, 1);
  113. char ok;
  114. for (int i = 1;i <= n;i++)
  115. {
  116. for (int j = 1;j <= f;j++)
  117. {
  118. cin >> ok;
  119. if (ok == 'Y')
  120. AddEdge(2*n+j, 2*i-1, 1);
  121. }
  122. }
  123. for (int i = 1;i <= n;i++)
  124. {
  125. for (int j = 1;j <= d;j++)
  126. {
  127. cin >> ok;
  128. if (ok == 'Y')
  129. AddEdge(2*i, 2*n+f+j, 1);
  130. }
  131. }
  132. int res = MaxFlow();
  133. cout << res << endl;
  134. }
  135. return 0;
  136. }

HDU-4292-Food(最大流,Dinic)的更多相关文章

  1. HDU 4292 Food 最大流

    Food Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. HDU 4292 Food (网络流,最大流)

    HDU 4292 Food (网络流,最大流) Description You, a part-time dining service worker in your college's dining ...

  3. 网络流之最大流Dinic算法模版

    /* 网络流之最大流Dinic算法模版 */ #include <cstring> #include <cstdio> #include <queue> using ...

  4. poj-1459-最大流dinic+链式前向星-isap+bfs+stack

    title: poj-1459-最大流dinic+链式前向星-isap+bfs+stack date: 2018-11-22 20:57:54 tags: acm 刷题 categories: ACM ...

  5. 网络流之最大流Dinic --- poj 1459

    题目链接 Description A power network consists of nodes (power stations, consumers and dispatchers) conne ...

  6. 网络最大流Dinic

    1.什么是网络最大流 形象的来说,网络最大流其实就是这样一个生活化的问题:现在有一个由许多水管组成的水流系统,每一根管道都有自己的最大通过水流限制(流量),超过这个限制水管会爆(你麻麻就会来找你喝茶q ...

  7. HDU 3572 Task Schedule(拆点+最大流dinic)

    Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  8. HDU 4292:Food(最大流)

    http://acm.hdu.edu.cn/showproblem.php?pid=4292 题意:和奶牛一题差不多,只不过每种食物可以有多种. 思路:因为食物多种,所以源点和汇点的容量要改下.还有D ...

  9. (网络流 最大流 Dinic || SAP)Control -- hdu --4289

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4289 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  10. H - Food - hdu 4292(简单最大流)

    题目大意:有N个人,然后有F种食品和D种饮料,每个人都有喜欢的饮料和食品,求出来这些食品最多能满足多少人的需求. 输入描述: 分析:以前是做过类似的题目的,不过输入的信息量比较大,还是使用邻接表的好些 ...

随机推荐

  1. 【ABAP系列】SAP ABAP 关于FUNCTION-POOL的理解

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP 关于FUNCT ...

  2. 【Python开发】【神经网络与深度学习】网络爬虫之图片自动下载器

    python爬虫实战--图片自动下载器 之前介绍了那么多基本知识[Python爬虫]入门知识(没看的赶紧去看)大家也估计手痒了.想要实际做个小东西来看看,毕竟: talk is cheap show ...

  3. discuz 设置

    veikei_dz_com_20120821_gray_free 模板  论坛 瀑布流 需要在后台设置  论坛--板块管理--编辑对应板块--扩展设置--开启图片列表模式 FAQ 帮助页面 在后台管理 ...

  4. Spring Boot(十七):使用 Spring Boot 上传文件

      上传文件是互联网中常常应用的场景之一,最典型的情况就是上传头像等,今天就带着带着大家做一个 Spring Boot 上传文件的小案例. 1.pom 包配置 我们使用 Spring Boot 版本 ...

  5. 2019JAVA第八次实验报告

    班级 计科二班 学号 20188442 姓名 吴怡君 完成时间 2019.11.1 评分等级 课程作业: 将奇数位小写字母改写为大写字母(用文件输出) 实验代码: package Domon7; im ...

  6. mysql中char,varchar与text类型的区别

      关于char,varchar与text平时没有太在意,一般来说,可能现在大家都是用varchar.但是当要存储的内容比较大时,究竟是选择varchar还是text呢?不知道...... text  ...

  7. 拼音检查python

    #coding=utf-8 #!/usr/bin/python import sys, re, collections #读入文件 def read_file(filename): try: fp = ...

  8. oracle ojdbc 版本须对应,否则日期字段查询结果与实际值可能不一致

    1. 数据库版本:select * from v$version; 2. 版本对应:

  9. 【网络安全】window 快速搭建 ftp 及 多种访问方式

    在局域网里面使用ftp传输文件比使用qq等软件传输速度快很多,但是搭建ftp很多时候需要下载相应的支持软件,其实不必下载相关的软件,因为window自带ftp功能. 演示操作系统:windows10 ...

  10. vue-注册全局过滤器

    import Vue from 'vue'; import dayjs from 'dayjs'; const filters = { formatDate(date, format = 'YYYY- ...