hdu4292 Food 最大流
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.
题意:有若干人,他们各自有喜欢的食物和饮料,只有当获得一种他们喜欢的食物和一种他们喜欢的饮料,才算获得了服务。饮料和食物都有总数,所以只能服务一部分人。问最多能服务多少人。
分开建边,先超级源点和食物建边,流量是食物的数量。再是食物到人,流量1,再人到饮料,流量1,再饮料到超级汇点,流量是饮料的数量,这样就可以由人节点来控制一条增广路流量一定是1,即满足一个人的需求。
#include<stdio.h>
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int maxm=;
const int INF=0x3f3f3f3f; struct edge{
int from,to,f;
edge(int a,int b,int c):from(a),to(b),f(c){}
}; struct dinic{
int s,t,m;
vector<edge>e;
vector<int>g[maxm];
bool vis[maxm];
int cur[maxm],d[maxm]; void init(int n){
for(int i=;i<=n;i++)g[i].clear();
e.clear();
} void add(int a,int b,int c){
e.push_back(edge(a,b,c));
e.push_back(edge(b,a,));
m=e.size();
g[a].push_back(m-);
g[b].push_back(m-);
} bool bfs(){
memset(vis,,sizeof(vis));
queue<int>q;
q.push(s);
vis[s]=;
d[s]=;
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=;i<g[u].size();i++){
edge tmp=e[g[u][i]];
if(!vis[tmp.to]&&tmp.f>){
d[tmp.to]=d[u]+;
vis[tmp.to]=;
q.push(tmp.to);
}
}
}
return vis[t];
} int dfs(int x,int a){
if(x==t||a==)return a;
int flow=,f;
for(int& i=cur[x];i<g[x].size();i++){
edge& tmp=e[g[x][i]];
if(d[tmp.to]==d[x]+&&tmp.f>){
f=dfs(tmp.to,min(a,tmp.f));
tmp.f-=f;
e[g[x][i]^].f+=f;
flow+=f;
a-=f;
if(a==)break;
}
}
if(flow==)d[x]=-;
return flow;
} int mf(int s,int t){
this->s=s;
this->t=t;
int flow=;
while(bfs()){
memset(cur,,sizeof(cur));
flow+=dfs(s,INF);
}
return flow;
}
}; char ss[]; int main(){
int n,f,d;
while(scanf("%d%d%d",&n,&f,&d)!=EOF){
int i,j;
dinic D;
D.init(f+*n+d+);
for(i=f+;i<=f+n;i++){
D.add(i,i+n,);
}
for(i=;i<=f;i++){
int a;
scanf("%d",&a);
D.add(,i,a);
}
for(i=;i<=d;i++){
int a;
scanf("%d",&a);
D.add(f+*n+i,f+*n+d+,a);
}
for(i=;i<=n;i++){
scanf("%s",ss+);
for(j=;j<=f;j++){
if(ss[j]=='Y')D.add(j,f+i,);
}
}
for(i=;i<=n;i++){
scanf("%s",ss+);
for(j=;j<=d;j++){
if(ss[j]=='Y')D.add(f+n+i,f+*n+j,);
}
}
printf("%d\n",D.mf(,f+*n+d+));
}
return ;
}
hdu4292 Food 最大流的更多相关文章
- HDU4292 Food —— 最大流 + 拆点
题目链接:https://vjudge.net/problem/HDU-4292 Food Time Limit: 2000/1000 MS (Java/Others) Memory Limit ...
- hdu4292 Food 最大流模板题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4292 题意:水和饮料,建图跑最大流模板. 我用的是学长的模板,最然我还没有仔细理解,不过这都不重要直接 ...
- HDU4292(KB11-H 最大流)
Food Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 最大流——hdu4292(类似poj3281 带间隔的流)
#include<bits/stdc++.h> using namespace std; #define maxn 100005 #define inf 0x3f3f3f3f ]; int ...
- [hdu4292]最大流,拆点
题意:给定每个人所喜欢的食物和饮料种类以及每种食物和饮料的数量,一个人需要一种食物和一种饮料(数量为1即可),问最多满足多少人的需要 思路:由于食物和饮料对于人来说需要同时满足,它们是“与”的关系,所 ...
- HDU 4292 Food (网络流,最大流)
HDU 4292 Food (网络流,最大流) Description You, a part-time dining service worker in your college's dining ...
- HDU-4292-Food(最大流,Dinic)
链接: https://vjudge.net/problem/HDU-4292 题意: You, a part-time dining service worker in your college's ...
- 使用C#处理基于比特流的数据
使用C#处理基于比特流的数据 0x00 起因 最近需要处理一些基于比特流的数据,计算机处理数据一般都是以byte(8bit)为单位的,使用BinaryReader读取的数据也是如此,即使读取bool型 ...
- HTML 事件(三) 事件流与事件委托
本篇主要介绍HTML DOM中的事件流和事件委托. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4 ...
随机推荐
- windows 日常使用
打开任务管理器:shift+ctrl+esc 各种快捷打开的方式 regedit.msc 注册表 gpedit.msc 组策略 lusrmgr.msc本地用户和组 CMD命令窗口打开任务管理: tas ...
- jquery 共用函数
ready()方法 $(doxument).ready(fucntion(){ }) $().ready(function(){ }) $(function(){ }) 当文档加载后激活函数: ...
- Win10系列:C#应用控件基础3
CheckBox控件 在应用程序的开发过程中开发者经常使用一组CheckBox控件来显示多个复选框,让用户从中选择一个或多个.当用户勾选复选框后,被选中的复选框会被标记为勾选状态,再次点击此复选框可取 ...
- 双向链表--首页大小不一卡片排序 --- react --- js
1.4中类型(grid_type)的卡片:1:大方块:2:竖长块:3:横长块:4:小方块 var order = 0; // 创建链表 function List(head) { this.head ...
- JavaScrip(三)JavaScrip变量高级操作(字符串,数组,日期)
一:字符串 charAt() 返回指定位置的字符 indexof() 返回指定字符串首次出现的位置 replace() 替换指定的字符 concat() 连接两个或多个字符串 substr(start ...
- TypeError: write() argument must be str, not bytes报错原因及Python3写入二进制文件方法
Python2随机写入二进制文件: with open('/python2/random.bin','w') as f: f.write(os.urandom(10)) 但使用Python3会报错: ...
- Cracking The Coding Interview 1.5
//原文: // // Write a method to replace all spaces in a string with '%20'. // #include <iostream> ...
- 《图解TCP/IP》读书笔记(转)
reference: https://www.cnblogs.com/edisonchou/p/5987827.html 一.国际惯例:书托 这是一本图文并茂的网络管理技术书籍,旨在让广大读者理解TC ...
- B2C B2B C2C O2O模式的介绍
b2c:天猫 商家对客户 c2c:淘宝 客户到客户(卖家也是阿里公司的客户) o2o:美团 线上花费,下 ...
- jaxb 组装及解析xml
参考 http://blog.csdn.net/yanan_seachange/article/details/7325708 a.添加依赖 b.建立绑定关系 c.测试 a.添加依赖 <depe ...