Food

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

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-F-人-人-D-T
代码
//зїеп:1085422276
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef __int64 ll;
using namespace std;
const int inf = ;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
} //*******************************
namespace NetFlow
{
const int MAXN=,MAXM=,inf=1e9;
struct Edge
{
int v,c,f,nx;
Edge() {}
Edge(int v,int c,int f,int nx):v(v),c(c),f(f),nx(nx) {}
} E[MAXM];
int G[MAXN],cur[MAXN],pre[MAXN],dis[MAXN],gap[MAXN],N,sz;
void init(int _n)
{
N=_n,sz=; memset(G,-,sizeof(G[])*N);
}
void link(int u,int v,int c)
{
E[sz]=Edge(v,c,,G[u]); G[u]=sz++;
E[sz]=Edge(u,,,G[v]); G[v]=sz++;
}
int ISAP(int S,int T)
{//S -> T
int maxflow=,aug=inf,flag=false,u,v;
for (int i=;i<N;++i)cur[i]=G[i],gap[i]=dis[i]=;
for (gap[S]=N,u=pre[S]=S;dis[S]<N;flag=false)
{
for (int &it=cur[u];~it;it=E[it].nx)
{
if (E[it].c>E[it].f&&dis[u]==dis[v=E[it].v]+)
{
if (aug>E[it].c-E[it].f) aug=E[it].c-E[it].f;
pre[v]=u,u=v; flag=true;
if (u==T)
{
for (maxflow+=aug;u!=S;)
{
E[cur[u=pre[u]]].f+=aug;
E[cur[u]^].f-=aug;
}
aug=inf;
}
break;
}
}
if (flag) continue;
int mx=N;
for (int it=G[u];~it;it=E[it].nx)
{
if (E[it].c>E[it].f&&dis[E[it].v]<mx)
{
mx=dis[E[it].v]; cur[u]=it;
}
}
if ((--gap[dis[u]])==) break;
++gap[dis[u]=mx+]; u=pre[u];
}
return maxflow;
}
bool bfs(int S,int T)
{
static int Q[MAXN]; memset(dis,-,sizeof(dis[])*N);
dis[S]=; Q[]=S;
for (int h=,t=,u,v,it;h<t;++h)
{
for (u=Q[h],it=G[u];~it;it=E[it].nx)
{
if (dis[v=E[it].v]==-&&E[it].c>E[it].f)
{
dis[v]=dis[u]+; Q[t++]=v;
}
}
}
return dis[T]!=-;
}
int dfs(int u,int T,int low)
{
if (u==T) return low;
int ret=,tmp,v;
for (int &it=cur[u];~it&&ret<low;it=E[it].nx)
{
if (dis[v=E[it].v]==dis[u]+&&E[it].c>E[it].f)
{
if (tmp=dfs(v,T,min(low-ret,E[it].c-E[it].f)))
{
ret+=tmp; E[it].f+=tmp; E[it^].f-=tmp;
}
}
}
if (!ret) dis[u]=-; return ret;
}
int dinic(int S,int T)
{
int maxflow=,tmp;
while (bfs(S,T))
{
memcpy(cur,G,sizeof(G[])*N);
while (tmp=dfs(S,T,inf)) maxflow+=tmp;
}
return maxflow;
}
}
using namespace NetFlow;
int main()
{
int n,f,d;
int fs,ds;
while(scanf("%d%d%d",&n,&f,&d)!=EOF){
init();
for(int i=;i<=f;i++)
{
fs=read();
link(,i,fs);
}
for(int i=;i<=d;i++)
{
ds=read();
link(i+,,ds);
}
char ch[];
for(int i=;i<=n;i++)
{
scanf("%s",ch);
for(int j=;j<f;j++)
{
if(ch[j]=='Y'){
link(j+,+i,);
}
}
}
for(int i=;i<=n;i++)
{
scanf("%s",ch);
for(int j=;j<d;j++)
{
if(ch[j]=='Y'){
link(+i,j++,);
}
}
}//
for(int i=;i<=n;i++)link(+i,+i,);
printf("%d\n",ISAP(,));//cout<<1111<<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. hdu 4292 最大流 水题

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

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

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

  5. HDU 4292 Food (拆点最大流)

    题意:N个人,F种食物,D种饮料,给定每种食物和饮料的量.每个人有自己喜欢的食物和饮料,如果得到自己喜欢的食物和饮料才能得到满足.求最大满足的人数. 分析:如果只是简单地N个人选择F种食物的话可以用二 ...

  6. HDU 4292 Food (建图思维 + 最大流)

    (点击此处查看原题) 题目分析 题意:某个餐馆出售f种食物,d种饮料,其中,第i种食物有fi份,第i种饮料有di份:此时有n个人来餐馆吃饭,这n个人必须有一份食物和一份饮料才会留下来吃饭,否则,他将离 ...

  7. HDU 3549 网络最大流再试

    http://acm.hdu.edu.cn/showproblem.php?pid=3549 同样的网络最大流 T了好几次原因是用了cout,改成printf就A了 还有HDU oj的编译器也不支持以 ...

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

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

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

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

随机推荐

  1. linux文件系统模拟

    #include "stdio.h" #include <stdlib.h> //#include <conio.h> #include <strin ...

  2. javax.inject中@Inject、@Named、@Qualifier和@Provider用法

    @Inject @Inject支持构造函数.方法和字段注解,也可能使用于静态实例成员.可注解成员可以是任意修饰符(private,package-private,protected,public).注 ...

  3. javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection

    客户端向服务器发送数据时,份两种情况,SSL单向验证和SSL双向验证 1.SSL单向验证时 代码如下: import java.io.IOException; import java.util.Has ...

  4. thinkphp中field方法

    hinkPHP的CURD操作中有很多非常实用的方法,从这篇开始,我们会为大家一一介绍. 首先为大家介绍下field方法的用法.field属于模型的连贯操作方法之一,主要目的是标识要返回或者操作的字段, ...

  5. Linux 中的 wheel 组和 staff 组

    wheel 组的概念 wheel 组的概念继承自 UNIX.当服务器需要进行一些日常系统管理员无法执行的高级维护时,往往就要用到 root 权限:而“wheel” 组就是一个包含这些特殊权限的用户池: ...

  6. [Effective JavaScript 笔记]第26条:使用bind方法实现函数的柯里化

    bind方法的作用,除了有绑定函数到对象外,我们来看看bind方法的一些其它应用. 简单示例 例子:假设有一个装配URL字符串的简单函数.代码如下 function simpleURL(protoco ...

  7. 台大《机器学习基石》课程感受和总结---Part 1(转)

    期末终于过去了,看看别人的总结:http://blog.sina.com.cn/s/blog_641289eb0101dynu.html 接触机器学习也有几年了,不过仍然只是个菜鸟,当初接触的时候英文 ...

  8. Linux init进程详解

    init模块 一般来说,Linux程序只能用另一个Linux程序启动.例如,登录Linux终端程序Mingetty. 但终端程序又由谁启动呢?在计算机上启动Linux时,内核装入并启动init程序. ...

  9. zb的生日

    http://acm.nyist.net/JudgeOnline/problem.php?pid=325 zb的生日 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 ...

  10. HDOJ 2066 floyed优化算法

    一个人的旅行 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...