Food
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4539 Accepted Submission(s): 1536

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


题意:
已知有N位客人,F种食物,D种饮品,每种食物和饮品有自己对应的数量,每个客人有自己对应喜爱的食物和饮品,求最大能满足多少位客人。


题解:
这道题其实和POJ3281是一样的,将人拆点后放在食物和饮品之间就可以了。
从此也可以总结出,像这样一个有限的物体种类将另外两个物体种类联系起来的题,这个物体都放在两个物体中间建图。
顺便多嘴一句,这道题如果用cin,最好把同步关掉。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
using namespace std;
int N,F,D;
const int MAXN = 100010;//点数的最大值
const int MAXM = 400010;//边数的最大值
const int INF = 0x3f3f3f3f;
struct Edge
{int to,next,cap,flow;
} edge[MAXM]; //注意是MAXM
int tol;
int head[MAXN];
int gap[MAXN],dep[MAXN],pre[MAXN],cur[MAXN];
void init()
{tol = 0;memset(head,-1,sizeof(head));
}
//加边,单向图三个参数,双向图四个参数
void addedge(int u,int v,int w,int rw=0)
{edge[tol].to = v;edge[tol].cap = w;edge[tol].next = head[u];edge[tol].flow = 0;head[u] = tol++;edge[tol].to = u;edge[tol].cap = rw;edge[tol].next = head[v];edge[tol].flow = 0;head[v]=tol++;
}
//输入参数:起点、终点、点的总数
//点的编号没有影响,只要输入点的总数
int sap(int start,int end,int N)
{memset(gap,0,sizeof(gap));memset(dep,0,sizeof(dep));memcpy(cur,head,sizeof(head));int u = start;pre[u] = -1;gap[0] = N;int ans = 0;while(dep[start] < N){if(u == end){int Min = INF;for(int i = pre[u]; i != -1; i = pre[edge[i^1].to])if(Min > edge[i].cap - edge[i].flow)Min = edge[i].cap - edge[i].flow;for(int i = pre[u]; i != -1; i = pre[edge[i^1].to]){edge[i].flow += Min;edge[i^1].flow -= Min;}u = start;ans += Min;continue;}bool flag = false;int v;for(int i = cur[u]; i != -1; i = edge[i].next){v = edge[i].to;if(edge[i].cap - edge[i].flow && dep[v]+1 == dep[u]){flag = true;cur[u] = pre[v] = i;break;}}if(flag){u = v;continue;}int Min = N;for(int i = head[u]; i != -1; i = edge[i].next)if(edge[i].cap - edge[i].flow && dep[edge[i].to] < Min){Min = dep[edge[i].to];cur[u] = i;}gap[dep[u]]--;if(!gap[dep[u]])return ans;dep[u] = Min+1;gap[dep[u]]++;if(u != start) u = edge[pre[u]^1].to;}return ans;
}
int main(void)
{ios::sync_with_stdio(false);int tmp;string str;while(cin >> N >> F >> D){init();for(int i=1;i<=F;i++){cin >> tmp;addedge(0,i,tmp);}for(int i=F+1;i<=F+D;i++){cin >> tmp;addedge(i,D+F+2*N+1,tmp);}for(int i=1;i<=N;i++){cin >> str;for(int j=0;j<F;j++)if(str[j]=='Y')addedge(j+1,D+F+i,INF);}for(int i=1;i<=N;i++){cin >> str;for(int j=0;j<D;j++)if(str[j]=='Y')addedge(D+F+N+i,F+j+1,INF);}for(int i=1;i<=N;i++)addedge(D+F+i,D+F+N+i,1);cout << sap(0,D+F+2*N+1,D+F+2*N+2) << endl;}return 0;
}

拆点最大流-HDU-4292-Food相关推荐

  1. hdu 4292 Food 最大流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4292 You, a part-time dining service worker in your c ...

  2. HDU - 4292 Food(最大流+思维建边)

    题目链接:点击查看 题目大意:作为食堂管理人,现在有n个学生需要打饭,每个学生需要一个饮料和食物才能满足,每个学生可以同时接受多种不同的食物和饮料,现在给出每种食物和饮料的个数,问最多能让多少学生满足 ...

  3. hdu 4560 拆点最大流 ***

    题意: 2013年一开始,一档音乐节目"我是歌手"就惊艳了大家一回.闲话少说,现在,你成为了这档节目的总导演,你的任务很简单,安排每一期节目的内容. 现 在有N个歌手,M种歌曲流派 ...

  4. HDU 4292 Food (成都赛区网络赛第五题,拆点网络流)

      题意:跟POJ3281基本上一样的拆点网络流. 建图:建一超级源点和一超级汇点,源点与食物相连,边权为其数量,汇点与饮料相连,边权也为其数量,把人分成两个点,之间的边权为1.每个人与之需要的食物和 ...

  5. HDU 4292 Food(dinic +拆点)

    题目链接 我做的伤心了,不知是模版效率低,还是错了,交上就是TLE,找了份别人的代码,改了好几下终于过了.. 1 #include <cstdio> 2 #include <cstr ...

  6. POJ 2391 Ombrophobic Bovines ★(Floyd+二分+拆点+最大流)

    [题意]有n块草地,一些奶牛在草地上吃草,草地间有m条路,一些草地上有避雨点,每个避雨点能容纳的奶牛是有限的,给出通过每条路的时间,问最少需要多少时间能让所有奶牛进入一个避雨点. 和POJ2112很类 ...

  7. 最大流 hdu 4183

    /** hdu 4183 求两点之间来回不重复的两条路就是要求从起点到终点至少有两条不重复的路径,最大流大于等于2即可 **/#include <iostream> #include &l ...

  8. Food HDU - 4292 网络流

    题意: 有n个人,f种食物和d种饮料,每种饮料和食物的个数已知,假设一个人拿到一个自己喜欢的食物或饮料,那个人就会感到满足. 最多能有几个人满足? 思路:拆点建图. 一个人必须又要饮料又要食物,假设我 ...

  9. BZOJ 1070 拆点 费用流

    1070: [SCOI2007]修车 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 5860  Solved: 2487 [Submit][Statu ...

  10. 网络流(最大流) HDU 1565 方格取数(1) HDU 1569 方格取数(2)

    HDU 1565 方格取数(1) 给你一个n*n的格子的棋盘,每个格子里面有一个非负数. 从中取出若干个数,使得任意的两个数所在的格子没有公共边,就是说所取的数所在的2个格子不能相邻,并且取出的数的和 ...

最新文章

  1. 在Ubuntu 16.04.1 LTS上安装ATS 6.2.1 LTS实录
  2. 给普通用户赋予docker权限
  3. linux 管道使用方法,Linux 管道命令
  4. idea插件手动安装
  5. nginx echo 输出 检查配置正确性
  6. 今日听闻这几款手机软件比较火爆 果然名不虚传!
  7. linux环境配置与使用合集
  8. word怎么改正错误单词_在word 里要怎么让电脑自动识别错误的英语单词?
  9. 三连击(升级版)(洛谷-P1618)
  10. SpringBoot 2 要不要升级
  11. devc 能优化吗_小网站能做seo优化吗?如何为小公司网站做seo优化?
  12. Drool规则引擎详解(转)
  13. 支持向量回归(SVR)的详细介绍以及推导算法
  14. 智能世界的罗马是怎样建成的?
  15. cpu显示无效查询 wmic_Windows WMIC命令使用详解(附实例)
  16. Ubuntu14.04 使用本地摄像头跑ORB SLAM2
  17. 几款U盘数据恢复的软件使用测评
  18. 基于Conv3D实现三维立体MNIST数据集分类
  19. Python让Excel飞起来—批量进行数据分析
  20. Web端测试——F12的代码调试与抓包

热门文章

  1. SpringCloud之一eureka注册中心(Greenwich版本)
  2. 简单的 PHP 抽奖程序
  3. Teigha .dwg文件开发——从零开始
  4. 学习“orang's 一个操作系统的实现”的朋友必看
  5. 使命召唤手游怎么显示服务器无响应,使命召唤手游无法进入怎么处理
  6. matlab画频域横坐标,离散傅里叶变换频域横坐标问题
  7. 三星s7572无法显示toast的问题解决
  8. 手动搭建transformer模型进行时序预测,股票预测
  9. 【自动化】人工智能企业自动化的关键现状和战略影响
  10. Windows主机日志分析办法与思路