链接:

http://acm.hdu.edu.cn/showproblem.php?pid=4292

Food

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

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
 
除建图外,别的似乎就是模板

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <queue>
#include <algorithm>
using namespace std; #define N 1000
#define INF 0x3f3f3f3f int G[N][N], Layer[N]; bool BFS(int S, int E)
{
queue<int>Q;
Q.push(S); memset(Layer, , sizeof(Layer));
Layer[S] = ; while(Q.size())
{
int u = Q.front(); Q.pop(); if(u==E) return true; for(int i=; i<=E; i++)
{
if(Layer[i]== && G[u][i])
{
Layer[i]=Layer[u]+;
Q.push(i);
}
}
}
return false;
} int DFS(int u, int MaxFlow, int E)
{
if(u==E) return MaxFlow; int uflow=;
for(int i=; i<=E; i++)
{
if(G[u][i] && Layer[u]+==Layer[i])
{
int flow = min(G[u][i], MaxFlow-uflow);
flow = DFS(i, flow, E); G[u][i] -= flow;
G[i][u] += flow;
uflow += flow; if(uflow==MaxFlow) break;
}
} if(uflow==) Layer[u] = ; return uflow;
} int Dinic(int S, int E)
{
int ans = ; while(BFS(S, E))
ans += DFS(S, INF, E); return ans;
} int main()
{
int n, F, D; while(scanf("%d%d%d", &n, &F, &D)!=EOF)
{
int i, j, a[N], b[N];
char s[N]; memset(G, , sizeof(G)); for(i=; i<=F; i++)
scanf("%d", &a[i]);
for(i=; i<=D; i++)
scanf("%d", &b[i]); for(i=; i<=n; i++)
G[i][i+n] = ;
for(i=n*+; i<=n*+F; i++)
G[][i] = a[i-*n];
for(i=n*+F+; i<=n*+F+D; i++)
G[i][n*+F+D+] = b[i-n*-F]; for(i=; i<=n; i++)
{
scanf("%s", s); for(j=; j<F; j++)
if(s[j]=='Y')
G[n*+j+][i] = ;
} for(i=; i<=n; i++)
{
scanf("%s", s); for(j=; j<=D; j++)
if(s[j]=='Y')
G[i+n][*n+F+j+] = ;
} printf("%d\n", Dinic(, *n+F+D+));
}
return ;
}

(网络流)Food -- hdu -- 4292的更多相关文章

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

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

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

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

  3. hdu 4292 Food 网络流

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

  4. H - Food HDU - 4292 网络流

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

  5. HDU 4292:Food(最大流)

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

  6. 网络流强化-HDU 3338-上下界限制最大流

    题意是: 一种特殊的数独游戏,白色的方格给我们填1-9的数,有些带数字的黑色方格,右上角的数字代表从他开始往右一直到边界或者另外一个黑格子,中间经过的白格子的数字之和要等于这个数字:左下角的也是一样的 ...

  7. hdu 4292 最大流 水题

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

  8. HDU 4292 Food 最大流

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

  9. HDU 4292 Food

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

随机推荐

  1. 微博短链接的生成算法(Java版本)

    最近看到微博的短链接真是很火啊,新浪.腾讯.搜狐等微博网站都加入了短链接的功能.之所以要是使用短链接,主要是因为微博只允许发140 字,如果链接地址太长的话,那么发送的字数将大大减少.短链接的主要职责 ...

  2. Hive新功能 Cube, Rollup介绍

    说明:Hive之cube.rollup,还有窗口函数,在传统关系型数据(Oracle.sqlserver)中都是有的,用法都很相似. GROUPING SETS GROUPING SETS作为GROU ...

  3. 给iOS开发新手送点福利,简述UIActivityIndicatorView的属性和用法

    UIActivityIndicatorView 1.   activityIndicatorViewStyle 设置指示器的样式 UIActivityIndicatorViewStyleWhiteLa ...

  4. 使用Fiddler实现网络限速

    Fiddler实现网络限速方法: 1.点击FiddlerScript 2.在脚本里相应的地方添加“2”处两行代码(不加注释),保存(Save Script) 第一行为请求延时3秒,第二行为响应延时1. ...

  5. Python2操作中文名文件乱码解决方案

    Python2默认是不支持中文的,一般我们在程序的开头加上#-*-coding:utf-8-*-来解决这个问题,但是在我用open()方法打开文件时,中文名字却显示成了乱码. 我先给大家说说Pytho ...

  6. uva-10785-模拟水题

    模拟题: 1• The name has a predefined length N.名字长度N2• The vowel value and consonant value of the name m ...

  7. ajax传参里含有特殊字符的坑

    问题场景:今天在测试自己手上的页面功能时,发现一个小bug,在用ajax向后台发数据时,只要参数中出现一些特殊字符,控制台会报错http 400的问题,其实就是特殊字符服务器不能解析.好了,问题是找到 ...

  8. 使用heroku创建应用时报错 heroku does not appear to be a git repository

    在跟着heroku的官方教程创建python应用时,到deploy-the-app这一步,要上传代码到heroku 的git仓库时,报的这个错误: 网上一搜,相关的答案居然极少,首页只出现一篇(还好这 ...

  9. codeforces:Prefix Sums分析和实现

    题目大意: 给出一个函数P,P接受一个数组A作为参数,并返回一个新的数组B,且B.length = A.length + 1,B[i] = SUM(A[0], ..., A[i]).有一个无穷数组序列 ...

  10. OLI 课程 & Java入学考试的五道题

    Unit  1:: Programming with Java ✔️ 机械.自动.不需要智慧地执行原始的内置指令. 字节码相同,JVM不同(体现平台) ✖️ In modern computers i ...