HDU 4292 Food
2015-09-17 11:29
337 查看
Food
Time Limit: 1000msMemory Limit: 32768KB
This problem will be judged on HDU. Original ID: 4292
64-bit integer IO format: %I64d Java class name: Main
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
2012 ACM/ICPC Asia Regional Chengdu Online解题:最大流,人拆点 边流为1
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 1010; struct arc { int to,flow,next; arc(int x = 0,int y = 0,int z = -1) { to = x; flow = y; next = z; } } e[maxn*maxn]; int head[maxn],cur[maxn],d[maxn],tot,S,T; void add(int u,int v,int flow) { e[tot] = arc(v,flow,head[u]); head[u] = tot++; e[tot] = arc(u,0,head[v]); head[v] = tot++; } queue<int>q; bool bfs() { while(!q.empty()) q.pop(); memset(d,-1,sizeof d); q.push(S); d[S] = 1; while(!q.empty()) { int u = q.front(); q.pop(); for(int i = head[u]; ~i; i = e[i].next) { if(e[i].flow && d[e[i].to] == -1) { d[e[i].to] = d[u] + 1; q.push(e[i].to); } } } return d[T] > -1; } int dfs(int u,int low) { if(u == T) return low; int tmp = 0,a; for(int &i = cur[u]; ~i; i = e[i].next) { if(e[i].flow && d[u]+1==d[e[i].to]&&(a=dfs(e[i].to,min(low,e[i].flow)))) { low -= a; tmp += a; e[i].flow -= a; e[i^1].flow += a; if(!low) break; } } if(!tmp) d[u] = -1; return tmp; } int dinic() { int ret = 0; while(bfs()) { memcpy(cur,head,sizeof cur); ret += dfs(S,INF); } return ret; } char str[maxn]; int main() { int N,F,D,flow; while(~scanf("%d%d%d",&N,&F,&D)) { memset(head,-1,sizeof head); S = tot = 0; T = 1000; for(int i = 1; i <= F; ++i) { scanf("%d",&flow); add(S,i,flow); } for(int i = 1; i <= D; ++i) { scanf("%d",&flow); add(F + i,T,flow); } for(int i = 1; i <= N; ++i) { add(F + D + i*2-1,F + D + i*2,1); scanf("%s",str); for(int j = 0; str[j]; ++j) if(str[j] == 'Y') add(j+1, F + D + i*2 - 1,INF); } for(int i = 1; i <= N; ++i) { scanf("%s",str); for(int j = 0; str[j]; ++j) if(str[j] == 'Y') add(F + D + i*2,F + j + 1,INF); } printf("%d\n",dinic()); } return 0; }
View Code
相关文章推荐
- js学习笔记
- 51nod 1391 01串 (dp+hash)
- latex幻灯片
- Hadoop —— Ubuntu单机环境部署Hadoop1.2.1
- 关于Eclipse中JSP,JS,HTML等代码自动提示的设置
- JS最常用 正则表达式3
- n个数操作k次每次一数乘以x,求所有数或值的最大值 "Or" Game
- 网页布局基础
- ArcGIS教程:山体阴影工作原理
- 常见C++内存池技术
- Java Web实现的基本MVC实例分析
- jprofiler监控linux下的tomcat
- [Java开发] cookie、session及实现记住密码,自动登录思路
- HuffmanTree
- java学习之LinkedHashSet
- 关于service启动方式
- ubuntu安装jdk以及配置java环境变量
- JDBC、Ibatis、Hibernate对比、以及优点缺点
- form 上传 html 代码
- HTML Table导出为Excel的方法