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.
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).
For each test case, please print a single line with one integer, the maximum number of people to be satisfied.
4 3 3 1 1 1 1 1 1 YYN NYY YNY YNY YNY YYN YYN NNY
3
HDU:https://vjudge.net/problem/HDU-4292
网络流,最大流
现在提供若干种饮料、食物,每种都有一定的数量。给定N个人对每一种食物和饮料的喜好,若给某人提供了其喜欢的食物和饮料,则称这个人是开心的。现在求能使最多的人开心的数量。
我们按照源点-食物-人-饮料-汇点的顺序建图。对于每一个食物,从源点连容量为其数量的的边,而对于每一个人,连接他和他所有喜欢的食物,容量都是1,。因为给一个人只提供一份食物和一份饮料,所以我们把人拆点,中间连容量为1的边。而对于饮料则是类似的,从人到他喜欢的饮料连容量为1的边,从饮料到汇点连容量为其数量的边。这样跑最大流即可。 关于最大流,这里使用Dinic,可以参考这篇文章
转载于:https://www.cnblogs.com/SYCstudio/p/7380827.html