hdu 4292 网络最大流
来源:互联网 发布:手机装修自己设计软件 编辑:程序博客网 时间:2024/05/14 21:13
http://acm.hdu.edu.cn/showproblem.php?pid=4292
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.
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).
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 31 1 11 1 1YYNNYYYNYYNYYNYYYNYYNNNY
Sample Output
3
/**hdu 4292 网络最大流题目大意:有F种食物,D种饮料,各有一定数量n个人,现在要求每个人的要求是1份食物1个饮料,问最多能满足多少人的要求解题思路:一看就是网络流的题。 建边思想:把n个人对应拆成个连个点i和i‘,之间连边权值1; 每种食物和喜欢其的i之间权值为1的边 每个人和他喜欢的饮料之间连权值为1的边 起点和每种食物之间连权值为该种食物数量的边; 每种饮料喝终点之间连权值为该种饮料数量的边。 跑一遍最大流即可。*/#include<cstdio>#include<iostream>#include<algorithm>#include<string.h>using namespace std;const int oo=1e9;const int mm=8811111;const int mn=1212;int node,src,dest,edge;int ver[mm],flow[mm],_next[mm];int head[mn],work[mn],dis[mn],q[mn];void prepare(int _node,int _src,int _dest){ node=_node,src=_src,dest=_dest; for(int i=0; i<node; ++i)head[i]=-1; edge=0;}void addedge(int u,int v,int c){ ver[edge]=v,flow[edge]=c,_next[edge]=head[u],head[u]=edge++; ver[edge]=u,flow[edge]=0,_next[edge]=head[v],head[v]=edge++;}bool Dinic_bfs(){ int i,u,v,l,r=0; for(i=0; i<node; ++i)dis[i]=-1; dis[q[r++]=src]=0; for(l=0; l<r; ++l) for(i=head[u=q[l]]; i>=0; i=_next[i]) if(flow[i]&&dis[v=ver[i]]<0) { dis[q[r++]=v]=dis[u]+1; if(v==dest)return 1; } return 0;}int Dinic_dfs(int u,int exp){ if(u==dest)return exp; for(int &i=work[u],v,tmp; i>=0; i=_next[i]) if(flow[i]&&dis[v=ver[i]]==dis[u]+1&&(tmp=Dinic_dfs(v,min(exp,flow[i])))>0) { flow[i]-=tmp; flow[i^1]+=tmp; return tmp; } return 0;}int Dinic_flow(){ int i,ret=0,delta; while(Dinic_bfs()) { for(i=0; i<node; ++i)work[i]=head[i]; while(delta=Dinic_dfs(src,oo))ret+=delta; } return ret;}int n,D,F,f[205],d[205];char a[1005];int main(){ while(~scanf("%d%d%d",&n,&F,&D)) { prepare(n*2+F+D+2,0,F+D+2*n+1); for(int i=1;i<=F;i++) { int x; scanf("%d",&x); addedge(src,i,x); } for(int i=1;i<=D;i++) { int x; scanf("%d",&x); addedge(i+F+n*2,dest,x); } for(int i=1;i<=n;i++) { addedge(i+F,i+n+F,1); scanf("%s",a+1); for(int j=1;j<=F;j++) { if(a[j]=='Y') addedge(j,i+F,1); } } for(int i=1;i<=n;i++) { scanf("%s",a+1); for(int j=1;j<=D;j++) { if(a[j]=='Y') addedge(i+F+n,F+n*2+j,1); } } printf("%d\n",Dinic_flow()); } return 0;}
0 0
- hdu 4292 网络最大流
- HDU-4292-网络流最大流
- HDU 4292Food(网络流之最大流)
- HDU 4292 Food 网络流最大流 拆点
- hdu 4292 Food 【图论-网络流-最大流-Dinic】
- hdu 3572 网络流 最大流
- HDU Escape (网络流,最大流)
- HDU kebab(网络流,最大流)
- hdu 1532 网络流-最大流 DINIC
- 图论 网络流 HDU 1532 最大流
- HDU-1532-网络流最大流
- HDU 1532 Drainage Ditches (最大网络流)
- HDU 1532 Drainage Ditches (最大网络流)
- hdu 1532 Drainage Ditches(最大网络流)
- HDU 3549 Flow Problem 最大网络流
- hdu 1532 最大网络流 Drainage Ditches
- hdu 3549 最大网络流 Flow Problem
- hdu 3572 Task Schedule 【网络最大流】
- 第十章 数组和指针
- js操作表格
- Java 对基本类型装箱的注意事项
- Android Service完全解析,关于服务你所需知道的一切(上)
- LeetCode | Path Sum
- hdu 4292 网络最大流
- Unique Binary Search Trees II
- java.lang ---基本类型
- JDBc连接数据库代码
- UNREFERENCED_PARAMETER的用处
- 提升place order 后的速度
- javascript中new Date()的浏览器兼容性问题
- Qt学习之路之QMessageBox消息框
- C语言中,关键字static的作用