博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Food HDU - 4292 (结点容量 拆点) Dinic
阅读量:4321 次
发布时间:2019-06-06

本文共 3546 字,大约阅读时间需要 11 分钟。

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 31 1 11 1 1YYNNYYYNYYNYYNYYYNYYNNNY

Sample Output

3

 

 

题意:

有一些个数有限的  不同种类的糖果 和 一些不同种类的饮料 , 每个人的口味不同,所以可以选择任意的糖果和饮料 , 每个都只选一个 

 求能满足最多的人的数量

 

解析:

建立超级源点s和超级汇点t  把s和糖果连在一起,边权为糖果的数量,  t和饮料连载一其,边权为饮料的数量, 然后把每一个人拆成两个点 其中边权为1

人和糖果、饮料 都建立边 边权为INF;

代码如下:

Dinic + 当前弧优化 

#include 
#include
#include
#include
#include
#define mem(a,b) memset(a,b,sizeof(a))using namespace std;const int maxn =101000, INF = 0x7fffffff;int cnt = 0, s, t;int head[maxn], d[maxn], cur[maxn];char str[300];struct node{ int u, v, c, next;}Node[maxn*4];void add_(int u, int v, int c){ Node[cnt].u = u; Node[cnt].v = v; Node[cnt].c = c; Node[cnt].next = head[u]; head[u] = cnt++;}void add(int u,int v,int c){ add_(u,v,c); add_(v,u,0);}bool bfs(){ queue
Q; mem(d,0); Q.push(s); d[s] = 1; while(!Q.empty()) { int u = Q.front(); Q.pop(); for(int i=head[u]; i!=-1; i=Node[i].next) { node e = Node[i]; if(!d[e.v] && e.c > 0) { d[e.v] = d[e.u] + 1; // cout<< e.v << " " << d[e.v] <
0) { int V = dfs(e.v, min(cap, e.c)); Node[i].c -= V; Node[i^1].c += V; cap -= V; ret += V; if(cap == 0) break; } } if(cap > 0) d[u] = -1; return ret;}int Dinic(){ int ans = 0; while(bfs()) { memcpy(cur,head,sizeof(head)); ans += dfs(s,INF); } return ans;}int main(){ int n, f, d; while(~scanf("%d%d%d",&n,&f,&d)) { cnt = 0; mem(head,-1); int temp; s = 0, t = f+d+n+n+10; for(int i=1; i<=f; i++) { scanf("%d",&temp); add(s,i,temp); } for(int i=1; i<=d; i++) { scanf("%d",&temp); add(f+i,t,temp); } for(int i=1; i<=n; i++) { scanf("%s",str); for(int j=0; j

 

转载于:https://www.cnblogs.com/WTSRUVF/p/9202751.html

你可能感兴趣的文章
c# 字段、属性get set
查看>>
td内容超出隐藏
查看>>
Spring CommonsMultipartResolver 上传文件
查看>>
Settings app简单学习记录
查看>>
SQLAlchemy
查看>>
多线程
查看>>
使用缓存的9大误区(下)转载
查看>>
appium键值对的应用
查看>>
MyEclipse 8.X 通用算法
查看>>
selenium.Phantomjs设置浏览器请求头
查看>>
分布式数据库如何选择,几种分布式数据库优缺点一览
查看>>
BZOJ 4443: 小凸玩矩阵【二分图】
查看>>
苹果 OS X制作u盘启动盘
查看>>
Jquery便利对象
查看>>
MVC: Connection String
查看>>
idea常用设置汇总
查看>>
Node.SelectNodes
查看>>
Lambda表达式语法进一步巩固
查看>>
Vue基础安装(精华)
查看>>
Git 提交修改内容和查看被修改的内容
查看>>