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 ...
随机推荐
- .clearfix:after(清除浮动)中各个属性及值详细解说
清除浮动.clearfix:after一词,从事web前端的朋友们对此不会陌生吧,下面为大家介绍的是.clearfix:after中用到的所有属性及值的含义,对此感兴趣的朋友可以参考下哈想,希望对大家 ...
- java将字符串根据空格进行分割,使用split方法
public class D { public static void main(String[] args) { String b = "Hello Java World"; S ...
- Java日期时间,以及相互转换
Java日期时间,以及相互转化 package com.study.string; import java.text.ParseException; import java.text.SimpleDa ...
- OOP⑸
1.封装: 继承: extends java只支持单根继承!(一个类只能有一个直接的父类) 是代码重用的一种方式! 将子类共有的属性和方法提取到父类中去! Object:超类/基类==>java ...
- 一个canvas的demo
该demo放于tomcat下运行,否则出现跨域错误 <!DOCTYPE html> <html> <head> <meta charset="utf ...
- vue-router-4-编程式导航
想要导航到不同的 URL,用 router.push 方法,会向 history 栈添加一个新的记录 <router-link> <==>router.push // 字符串 ...
- ios 设置本地化显示的app名称
内容的本地化这里不做介绍! 名称的本地化: 1.新建一个 Strings File文件,命名为InfoPlist,注意这里一定要命名为InfoPlist! 2.设置本地化信息:选择需要的语言! 3.填 ...
- aspnet core 2.0 发布之后没有 views文件夹
在项目文件里面 增加这个节点: MvcRazorCompileOnPublish 设置为false 是会发布views <PropertyGroup> <PackageTargetF ...
- ubuntu GUI程序开机自启设置
在 主目录下,即 $HOME路径下新建 或编辑 .gnomerc 文件,将开机启动脚本写在这里如下:gedit ~/.gnomerc#!/bin/bashcd /home/xxxx/openUI./o ...
- activiti 插件安装,以及初始化配置
1.安装插件 2.添加pom 3.配置activiti.cfg.xml 4.绘制业务流程图 MyProcess.bpmn 5.加载activiti数据表 6.创建流程 1.安装eclipse acti ...