Food

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2136    Accepted Submission(s): 745

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. 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
Source
构图是老生常谈的事情了。
S-->food连边food[i] ;
food-->man1连边1
man1-->man2连边1
mam2-->drink 连边1 ,
diink-->T连边dink[i]
#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
typedef long long LL ;
#define MAXN 1000
#define inf 2100000000
int g[MAXN][MAXN],level[MAXN];
int bfs(int n,int s,int t){
int que[],head,tail,i;
head=tail=;
que[tail++]=s;
memset(level,-,sizeof(level));
level[s]=;
while(head<tail){
int x=que[head++];
for(i=;i<=n;++i)
if((g[x][i])&&(level[i]==-)){
level[i]=level[x]+;
que[tail++]=i;
}
}
return level[t]+;
}
/*n为最大点,s起点 ,t终点 ,图中没有定点0,从1开始到n*/
int dinic(int n,int s,int t){
int maxflow=,i;
while(bfs(n,s,t)){
int pos,path[MAXN],cut=,low,find;
pos=;
path[pos++]=s;find=;
while(){
find=;
low=inf;
while((path[pos-]!=t)&&(find)){
find=;
for(i=;i<=n;++i)
if((level[i]==level[path[pos-]]+)&&(g[path[pos-]][i])){
path[pos++]=i;
find=;
break;
}
else if (i==n) break;
}
if(path[pos-]==t){
for(i=;i<pos-;++i){
if(low>g[path[i]][path[i+]]){
low=g[path[i]][path[i+]];
cut=i;
}
}
maxflow+=low;
for(i=;i<pos-;++i){
g[path[i]][path[i+]]-=low;
g[path[i+]][path[i]]+=low;
}
pos=cut+;
}
else{
if(pos==)
break;
else{
level[path[pos-]]=-;
pos--;
}
}
}
}
return maxflow;
} const int Max_N= ;
char str[Max_N][Max_N] ;
int food[Max_N] ;
int drink[Max_N] ;
int S ,T ;
int main(){
int F , N , D ;
while(scanf("%d%d%d",&N,&F,&D)!=EOF){
memset(g,,sizeof(g)) ;
for(int i=;i<=F;i++)
scanf("%d",&food[i]) ;
for(int i=; i<=D ;i++)
scanf("%d",&drink[i]) ;
for(int i=;i<=N;i++)
scanf("%s",str[i]+) ;
for(int i=;i<=N;i++)
for(int j=;j<=F;j++){
if(str[i][j]=='Y')
g[j][F+i]= ;
}
for(int i=;i<=N;i++)
scanf("%s",str[i]+) ;
for(int i=;i<=N;i++)
for(int j=;j<=D;j++){
if(str[i][j]=='Y')
g[F+N+i][F+N+N+j]= ;
}
for(int i=;i<=N;i++)
g[F+i][F+N+i]= ;
T=F+N+N+D+ ;
S=F+N+N+D++ ;
for(int i=;i<=D;i++)
g[F+N+N+i][T]=drink[i] ;
for(int i=;i<=F;i++)
g[S][i]=food[i] ;
cout<<dinic(S,S,T)<<endl ;
}
return ;
}

HDU 4292 Food的更多相关文章

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

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

  2. HDU 4292:Food(最大流)

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

  3. Food HDU - 4292 网络流 拆点建图

    http://acm.hdu.edu.cn/showproblem.php?pid=4292 给一些人想要的食物和饮料,和你拥有的数量,问最多多少人可以同时获得一份食物和一份饮料 写的时候一共用了2种 ...

  4. (网络流)Food -- hdu -- 4292

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4292 Food Time Limit: 2000/1000 MS (Java/Others)    Me ...

  5. hdu 4292 最大流 水题

    很裸的一道最大流 格式懒得排了,注意把人拆成两份,一份连接食物,一份连接饮料 4 3 3 //4个人,3种食物,3种饮料 1 1 1 //食物每种分别为1 1 1 1 //饮料每种数目分别为1 YYN ...

  6. HDU 4292 Food 最大流

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

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

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

  8. hdu 4292 Food 网络流

    题目链接 给你f种食物, 以及每种食物的个数, d种饮料, 以及个数, n个人, 以及每个人可以接受的食物种类和饮料种类. 每个人必须得到一种食物和一种饮料. 问最后得到满足的人的个数. 因为一个人只 ...

  9. Food HDU - 4292 (结点容量 拆点) Dinic

    You, a part-time dining service worker in your college’s dining hall, are now confused with a new pr ...

随机推荐

  1. CSS命名规则

    头:header  内容:content/container  尾:footer  导航:nav  侧栏:sidebar 栏目:column  页面外围控制整体布局宽度:wrapper  左右中:le ...

  2. [原]Fedora Linux环境下的应用工具总结

    一.办公类软件 1.Office办公:WPS 二.网络通信类软件 1.浏览器:Chrome 2.远程桌面:rdesktop(适用于Windows系列) 三.操作系统设置与优化 1.3D桌面管理:Com ...

  3. (转)Lambda表达式详解

    本文转载自:http://www.cnblogs.com/knowledgesea/p/3163725.html 前言 1.天真热,程序员活着不易,星期天,也要顶着火辣辣的太阳,总结这些东西. 2.夸 ...

  4. 【JdbcTemplete】JdbcTemplete代码详解--模板方法详解

    JdbcTemplete类层次结构 JdbcAccessor:对DataSource数据源进行管理和配置: JdbcOperations:定义了通过JDBC操作数据库的基本操作方法: JdbcTemp ...

  5. 查询SQLServer 服务器,执行过的SQL语句耗时!

    SELECT creation_time N'语句编译时间',last_execution_time N'上次执行时间',total_physical_reads N'物理读取总次数',total_l ...

  6. Apple dev travel

    Objective-C最基础语法之Class定义: http://mobile.51cto.com/iphone-281925.htm  Table View: http://www.appcoda. ...

  7. Studio之版本管理工具Git (图文教程)

    目前业界主流的版本管理工具主要是 svn/git.svn是1种集中式的代码管理工具,而git是1种散布式的代码管理工具,广受极客的爱好.而基于git的github更是全宇宙码农的提高逼格,深究技术的必 ...

  8. listview当选中某一个item时设置背景色其他的不变

    listview当选中某一个item时设置背景色其他的不变: 可以使用listview.setOnFoucsChangeListener(listener) ; /** * listview获得焦点和 ...

  9. UCOS-信号量(学习笔记)

    当事件控制块类型为OS_Event_Type_SEM类型时就是信号量,包含2个内容:信号量计数器OSEventcnt和等待列表OSEventTbl[]. 一创建信号量:OSSemCreat(int16 ...

  10. ylbtech-dbs:ylbtech-5,RI(报销发票系统)

    ylbtech-dbs:ylbtech-5,RI(报销发票系统) -- =============================================-- DatabaseName:Pur ...