题目链接

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. �阤 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. �阤 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

AC

  • 建边

    1. 源点到食物,权值为数量
    2. 食物到人,权值为inf
    3. 人到(拆点人),权值为1(保证不会浪费,同一个人得到多个)
    4. 拆点人到饮料,权值为inf
    5. 饮料到汇点,权值为数量
#include <iostream>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#define N 162000
#include <cstring>
#define ll long long
#define P pair<int, int>
#define mk make_pair
using namespace std;
int head[810], curedge[810], level[810];
int inf = 0x3f3f3f3f;
int n, f, d, cnt;
struct ac{int v, c, pre;
}edge[N];
void init() {cnt = 0;memset(head, -1, sizeof(head));memset(edge, 0, sizeof(edge));
}
void addedge(int u, int v, int c) {edge[cnt].v = v;edge[cnt].c = c;edge[cnt].pre = head[u];head[u] = cnt++;swap(u, v); edge[cnt].v = v;edge[cnt].c = 0;edge[cnt].pre = head[u];head[u] = cnt++;
}bool bfs(int s, int e) {queue<int> que;memset(level, 0, sizeof(level));level[s] = 1;que.push(s);while (!que.empty()) {int u = que.front();que.pop();for (int i = head[u]; i != -1; i = edge[i].pre) {if (level[edge[i].v]  ||  edge[i].c <= 0)   continue;level[edge[i].v] = level[u] + 1;que.push(edge[i].v);}}return level[e] != 0;
}
int dfs(int s, int e, int flow) {if (s == e) return flow;for (int &i = curedge[s]; i != -1; i = edge[i].pre) {if (level[edge[i].v] == level[s] + 1 && edge[i].c > 0) {int d = dfs(edge[i].v, e, min(flow, edge[i].c));if (d > 0) {edge[i].c -= d;edge[i ^ 1].c += d;return d;}}}return 0;
}
int Dinic(int s, int e) {int sum = 0;while (bfs(s, e)) {for (int i = 0; i <= e; ++i) {curedge[i] = head[i];}int d;while (d = dfs(s, e, inf)) {sum += d;}}return sum;
}
int main() {
#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);
#endifwhile (scanf("%d%d%d", &n, &f, &d) != EOF) {init();int start = 0, end =  f + n + n + d + 1;// 源点到食物 for (int i = 1; i <= f; ++i) {int t;scanf("%d", &t);addedge(start, i, t);}// 饮料到汇点 for (int j = 1; j <= d; ++j) {int t;scanf("%d", &t);addedge(f + n * 2 + j, end, t);}getchar();// 食物到人 for (int i = 1; i <= n; ++i) {char c;for (int j = 1; j <= f; ++j) {scanf("%c", &c);if (c == 'Y') {addedge(j, f + i, inf);}   }getchar();}// 人到饮料 for (int i = 1; i <= n; ++i) {char c;for (int j = 1; j <= d; ++j) {scanf("%c", &c);if (c == 'Y')   {addedge(f + n + i, f + n + n + j, inf);}}getchar();}// 拆点的同一个人之间建边 for (int i = 1; i <= n; ++i) {addedge(f + i, f + n + i, 1);}int ans = Dinic(start, end);printf("%d\n", ans);}return 0;
}

HDU Problem - 4292 Food(最大流, 建边)相关推荐

  1. HDU Problem - 3338 Kakuro Extension (最大流,建图)

    题目链接 Problem Description If you solved problem like this, forget it.Because you need to use a comple ...

  2. HDU Problem - 2732 Leapin' Lizards(最大流,拆点建边)

    题目链接 Problem Description Your platoon of wandering lizards has entered a strange room in the labyrin ...

  3. HDU - 4292 Food(最大流+思维建边)

    题目链接:点击查看 题目大意:作为食堂管理人,现在有n个学生需要打饭,每个学生需要一个饮料和食物才能满足,每个学生可以同时接受多种不同的食物和饮料,现在给出每种食物和饮料的个数,问最多能让多少学生满足 ...

  4. HDU Problem - 1533 Going Home(费用流板子题)

    题目链接 Problem Description On a grid map there are n little men and n houses. In each unit time, every ...

  5. hdu 4292 Food 最大流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4292 You, a part-time dining service worker in your c ...

  6. HDU Problem - 4289 Control(最大流)

    题目链接 Problem Description You, the head of Department of Security, recently received a top-secret inf ...

  7. HDU Problem - 4280 Island Transport(最大流)

    题目链接 Problem Description In the vast waters far far away, there are many islands. People are living ...

  8. HDU - 3338 Kakuro Extension(最大流+思维建边)

    题目链接:点击查看 题目大意:填数游戏,给出一个n*m的矩阵,矩阵中存在三种方块: 纯黑的方块:没什么用 纯白的方块:等待我们填数字的方块 黑色方块上有数字: 左下角有数字:当前黑色方块下面的白色方块 ...

  9. HDU - 2732 Leapin' Lizards(最大流+思维建边)

    题目链接:点击查看 题目大意:给出两个n*m的迷宫,第一个迷宫中表示每个柱子的耐久度,第二个迷宫表示的是每一只蜥蜴的位置,现在给出每只蜥蜴可以跳跃的最大曼哈顿距离,规定跳出迷宫边界就可以逃离迷宫,现在 ...

最新文章

  1. 想用Python学机器学习?Google大神替你写好了所有的编程示范代码
  2. 9、Java Swing JRadioButton:单选按钮组件
  3. 使用Jackson和Super类型令牌进行Json反序列化
  4. 使用GNS3和Cisco IOU搭建路由交换实验-安装篇
  5. 手把手教你移植RT-Thread系统
  6. idea 切换git仓库_Idea切换git分支及合并
  7. Atitit springboot mybatis spring 集成 Springboot1.4 mybatis3.4.6 /springbootMybatis 目录 1.1. 设置map
  8. java 天上掉东西游戏的源代码_【小游戏】前两天的小游戏终于调试成功了。。。。直接源代码...
  9. 帆软mysql迁移_平台数据迁移- FineReport帮助文档|报表开发|报表使用|学习教程
  10. 超实用一键破解网页不能复制/右键菜单限制的 Bookmarklet 收藏夹书签小工具
  11. Linux Spark安装教程
  12. open cv中文文档
  13. 关于HC05 蓝牙模块与与蓝牙模块连接
  14. 屌丝、小白怎么拿国内巨头offer
  15. 美联储数字货币最新进展
  16. Java-----四舍五入保留两位小数的方法
  17. QGIS 影像图黑色背景去除
  18. 《愤怒的小鸟》全系列游戏——风靡全国,空降奴改:愤怒的小猪来袭~(版本二)
  19. 图书预约管理系统的设计与实现
  20. WFU校赛题解 B、C、F

热门文章

  1. tomcat常见错误处理
  2. 重新实践《轻量级DJANGO》这本书
  3. JSON与js对象序列化
  4. UVa 590 Always on the run(简单链式DP)
  5. 极有收藏价值的一组难求纯4位数字.com域名 #8847#含义你懂的。 http://t.cn/ae9CTd
  6. Day11多态部分-6 【1.4 多态的应用以及注意事项】
  7. python3.7 ‘utf-8‘ codec can‘t decode byte 0xbe in position 0: invalid start byte
  8. 632. Smallest Range Covering Elements from K Lists 最小区间
  9. 数据库开发——MySQL——foreign key
  10. 信息学奥赛一本通(C++)在线评测系统——基础(一)C++语言——1102:与指定数字相同的数的个数