Food HDU - 4292 (结点容量 拆点) Dinic
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
题意:
有一些个数有限的 不同种类的糖果 和 一些不同种类的饮料 , 每个人的口味不同,所以可以选择任意的糖果和饮料 , 每个都只选一个
求能满足最多的人的数量
解析:
建立超级源点s和超级汇点t 把s和糖果连在一起,边权为糖果的数量, t和饮料连载一其,边权为饮料的数量, 然后把每一个人拆成两个点 其中边权为1
人和糖果、饮料 都建立边 边权为INF;
代码如下:
Dinic + 当前弧优化
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <cmath>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn =, INF = 0x7fffffff;
int cnt = , s, t;
int head[maxn], d[maxn], cur[maxn];
char str[];
struct node{
int u, v, c, next;
}Node[maxn*]; void add_(int u, int v, int c)
{
Node[cnt].u = u;
Node[cnt].v = v;
Node[cnt].c = c;
Node[cnt].next = head[u];
head[u] = cnt++;
} void add(int u,int v,int c)
{
add_(u,v,c);
add_(v,u,);
} bool bfs()
{
queue<int> Q;
mem(d,);
Q.push(s);
d[s] = ;
while(!Q.empty())
{
int u = Q.front(); Q.pop();
for(int i=head[u]; i!=-; i=Node[i].next)
{
node e = Node[i];
if(!d[e.v] && e.c > )
{
d[e.v] = d[e.u] + ;
// cout<< e.v << " " << d[e.v] <<endl;
Q.push(e.v);
if(e.v == t) return ;
}
}
}
// cout<< d[t] <<endl;
return d[t] != ;
} int dfs(int u,int cap)
{
if(u == t || cap == )
return cap;
int ret = ;
for(int &i=cur[u]; i!=-; i=Node[i].next)
{
node e = Node[i];
if(d[e.v] == d[e.u] + && e.c > )
{
int V = dfs(e.v, min(cap, e.c));
Node[i].c -= V;
Node[i^].c += V;
cap -= V;
ret += V;
if(cap == ) break;
}
}
if(cap > ) d[u] = -;
return ret;
} int Dinic()
{
int ans = ;
while(bfs())
{
memcpy(cur,head,sizeof(head));
ans += dfs(s,INF);
}
return ans;
}
int main()
{
int n, f, d;
while(~scanf("%d%d%d",&n,&f,&d))
{
cnt = ;
mem(head,-);
int temp;
s = , t = f+d+n+n+;
for(int i=; i<=f; i++)
{
scanf("%d",&temp);
add(s,i,temp);
}
for(int i=; i<=d; i++)
{
scanf("%d",&temp);
add(f+i,t,temp);
}
for(int i=; i<=n; i++)
{
scanf("%s",str);
for(int j=; j<f; j++)
{
if(str[j] == 'Y'){
add(j+,f+d+i,INF);
}
}
}
for(int i=; i<=n; i++)
add(f+d+i, f+d+n+i,);
for(int i=; i<=n; i++)
{
scanf("%s",str);
for(int j=; j<d; j++)
{
if(str[j] == 'Y')
add(f+d+n+i,f+j+,INF);
}
}
cout<< Dinic() <<endl;
} return ;
}
Food HDU - 4292 (结点容量 拆点) Dinic的更多相关文章
- HDU 4292 Food (网络流,最大流)
HDU 4292 Food (网络流,最大流) Description You, a part-time dining service worker in your college's dining ...
- poj-3436.ACM Computer Factory(最大流 + 多源多汇 + 结点容量 + 路径打印 + 流量统计)
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10940 Accepted: ...
- Food HDU - 4292 网络流 拆点建图
http://acm.hdu.edu.cn/showproblem.php?pid=4292 给一些人想要的食物和饮料,和你拥有的数量,问最多多少人可以同时获得一份食物和一份饮料 写的时候一共用了2种 ...
- UVA1658 Admiral 拆点法解决结点容量(路径不能有公共点,容量为1的时候) 最小费用最大流
/** 题目:UVA1658 Admiral 链接:https://vjudge.net/problem/UVA-1658 题意:lrj入门经典P375 求从s到t的两条不相交(除了s和t外,没有公共 ...
- HDU 4292 Food (拆点最大流)
题意:N个人,F种食物,D种饮料,给定每种食物和饮料的量.每个人有自己喜欢的食物和饮料,如果得到自己喜欢的食物和饮料才能得到满足.求最大满足的人数. 分析:如果只是简单地N个人选择F种食物的话可以用二 ...
- HDU 4292:Food(最大流)
http://acm.hdu.edu.cn/showproblem.php?pid=4292 题意:和奶牛一题差不多,只不过每种食物可以有多种. 思路:因为食物多种,所以源点和汇点的容量要改下.还有D ...
- HDU 3820 Golden Eggs (SAP | Dinic)
Golden Eggs Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 4292 Food (建图思维 + 最大流)
(点击此处查看原题) 题目分析 题意:某个餐馆出售f种食物,d种饮料,其中,第i种食物有fi份,第i种饮料有di份:此时有n个人来餐馆吃饭,这n个人必须有一份食物和一份饮料才会留下来吃饭,否则,他将离 ...
- (网络流)Food -- hdu -- 4292
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4292 Food Time Limit: 2000/1000 MS (Java/Others) Me ...
随机推荐
- C++11 并发指南二(std::thread 详解)
上一篇博客<C++11 并发指南一(C++11 多线程初探)>中只是提到了 std::thread 的基本用法,并给出了一个最简单的例子,本文将稍微详细地介绍 std::thread 的用 ...
- 学习Android(入门基础和实用教程)
为了方便大家学习,准备录制Android基础篇的视频教程, https://item.taobao.com/item.htm?spm=0.7095261.0.0.17a61debAKIDPI& ...
- tcp为什么是三次握手
刷知乎看到的,很可爱啊哈哈哈就顺手黏贴过来了 作者:大闲人柴毛毛链接:https://www.zhihu.com/question/24853633/answer/254224088来源:知乎著作权归 ...
- BZOJ4985 评分 二分答案、DP
传送门 题意:自己去看 答案满足单调性,所以考虑二分答案. 二分答案很好想,但是check并不是很好想. 考虑DP:设$f_i$表示队列中第$i$个人的分数$\geq \, mid$的代价,最开始$N ...
- ng-include文件实现ng-repeat
Angularjs实现自由度很高.比如ng-repeat可以以包含的文件中实现数据循环. 如: 当我们把这html文件被ng-include包含时,它完全能正常呈现对应的数据: 创建应用app: 创建 ...
- IntelliJ IDEA下自动生成Hibernate映射文件以及实体类
来自:https://blog.csdn.net/chenyunqiang/article/details/81026823 1.构建项目并添加项目结构配置以及配置初始参数 1.1.如图将基本的架子搭 ...
- 微服务监控zipkin+asp.net core
0.目录 整体架构目录:ASP.NET Core分布式项目实战-目录 监控目录:微服务监控zipkin.skywalking以及日志ELK监控系列 一.zipkin介绍 zipkin是一种分布式跟踪系 ...
- C#_Math函数总结
Math.abs() 计算绝对值. Math.acos() 计算反余弦值. Math.asin() 计算反正弦值. Math.atan() 计算反正切值. Math.atan2() 计算从x 坐标轴到 ...
- nginx通过https方式反向代理多实例tomcat
案例说明:前面一层nginx+Keepalived部署的LB,后端两台web服务器部署了多实例的tomcat,通过https方式部署nginx反向代理tomcat请求.配置一如下: 1)LB层的ngi ...
- 浅谈JS的作用域链(一)
JS的执行环境 执行环境(Execution context,EC)或执行上下文,是JS中一个极为重要的概念. 在JavaScript中有三种代码运行环境: Global Code JavaScrip ...