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 ...
随机推荐
- Win10系列:C#应用控件基础4
ComboBox控件 ComboBox控件包含一个不可编辑的文本框和一个下拉列表,这个下拉列表是由多个ComboBoxItem子元素组成的.使用ComboBox控件可以节省界面空间,因为ComboBo ...
- Date与时间戳的相互转换(Java)
1.Date对象转换为时间戳 Date date = new Date(); long times = date.getTime(); System.out.println(times); 效果如 ...
- 解决WDCP3环境gbk网站编码程序乱码问题
因为默认WDCP V3版本环境编码格式是UTF-8版本,如果我们程序采用的是GBK编码肯定都会有乱码问题. 我们到WDCP后台,"网站管理"-"PHP设置",看 ...
- relativeURL 相对URL的坑
我正在尝试实现一个使用RestKit的iOS应用程序.在我迄今为止看到的所有示例中,以下代码用于创建URL: NSURL *baseURL = [NSURL URLWithString:@" ...
- update-alternatives关键解疑
update-alternatives的用法网上到处又有,但有2个知识点好像都没怎么提到: 1.--install 里的参数link到底是啥意思,其实update-alternatives本质就是在/ ...
- nw.js的localStorage的物理储存位置
前言 因为在做美团外卖商家端的nw.js壳子项目,需要保证在壳子里面使用localStorage的数据可以持久化保存. 发现nw可以保存,即使删除应用重写打包也可以保存,所以解决了这个需求,但是还是需 ...
- matlab中diff的用法
若是diff(),括号里的元素为向量,那么前一个减后一个即为diff后的结果: 若diff(),括号里的元素为矩阵,那么下一行减上一行即为diff 后的结果:
- kubenetes pv(nfs) pvc 搭建
1:nfs-server的搭建. install the NFS Server: sudo apt install nfs-kernel-server 2:配置server. vim /etc/exp ...
- asp.net mvc 实现简单的实时消息推送
因为项目需要,需要在网页上实现消息的推送.在百度上搜索了一下,发现实现网页上的消息推送,可以使用asp.net 中的SignalR类库,当然也可以使用H5的WebSocket Ajax的轮回.当然此 ...
- pl/sql developer中dbms_output.put_line函数的运用
pl/sql developer中dbms_output.put_line函数可以打印想显示在屏幕上的信息,运用时需要注意几点: 1 必须处于begin ... end: 2 需要先执行 set ...