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,即满足一个人的需求。
1 #include<stdio.h> 2 #include<string.h> 3 #include<vector> 4 #include<queue> 5 #include<algorithm> 6 using namespace std; 7 const int maxm=1000; 8 const int INF=0x3f3f3f3f; 9 10 struct edge{ 11 int from,to,f; 12 edge(int a,int b,int c):from(a),to(b),f(c){} 13 }; 14 15 struct dinic{ 16 int s,t,m; 17 vector<edge>e; 18 vector<int>g[maxm]; 19 bool vis[maxm]; 20 int cur[maxm],d[maxm]; 21 22 void init(int n){ 23 for(int i=1;i<=n;i++)g[i].clear(); 24 e.clear(); 25 } 26 27 void add(int a,int b,int c){ 28 e.push_back(edge(a,b,c)); 29 e.push_back(edge(b,a,0)); 30 m=e.size(); 31 g[a].push_back(m-2); 32 g[b].push_back(m-1); 33 } 34 35 bool bfs(){ 36 memset(vis,0,sizeof(vis)); 37 queue<int>q; 38 q.push(s); 39 vis[s]=1; 40 d[s]=0; 41 while(!q.empty()){ 42 int u=q.front(); 43 q.pop(); 44 for(int i=0;i<g[u].size();i++){ 45 edge tmp=e[g[u][i]]; 46 if(!vis[tmp.to]&&tmp.f>0){ 47 d[tmp.to]=d[u]+1; 48 vis[tmp.to]=1; 49 q.push(tmp.to); 50 } 51 } 52 } 53 return vis[t]; 54 } 55 56 int dfs(int x,int a){ 57 if(x==t||a==0)return a; 58 int flow=0,f; 59 for(int& i=cur[x];i<g[x].size();i++){ 60 edge& tmp=e[g[x][i]]; 61 if(d[tmp.to]==d[x]+1&&tmp.f>0){ 62 f=dfs(tmp.to,min(a,tmp.f)); 63 tmp.f-=f; 64 e[g[x][i]^1].f+=f; 65 flow+=f; 66 a-=f; 67 if(a==0)break; 68 } 69 } 70 if(flow==0)d[x]=-1; 71 return flow; 72 } 73 74 int mf(int s,int t){ 75 this->s=s; 76 this->t=t; 77 int flow=0; 78 while(bfs()){ 79 memset(cur,0,sizeof(cur)); 80 flow+=dfs(s,INF); 81 } 82 return flow; 83 } 84 }; 85 86 char ss[250]; 87 88 int main(){ 89 int n,f,d; 90 while(scanf("%d%d%d",&n,&f,&d)!=EOF){ 91 int i,j; 92 dinic D; 93 D.init(f+2*n+d+5); 94 for(i=f+1;i<=f+n;i++){ 95 D.add(i,i+n,1); 96 } 97 for(i=1;i<=f;i++){ 98 int a; 99 scanf("%d",&a); 100 D.add(0,i,a); 101 } 102 for(i=1;i<=d;i++){ 103 int a; 104 scanf("%d",&a); 105 D.add(f+2*n+i,f+2*n+d+1,a); 106 } 107 for(i=1;i<=n;i++){ 108 scanf("%s",ss+1); 109 for(j=1;j<=f;j++){ 110 if(ss[j]=='Y')D.add(j,f+i,1); 111 } 112 } 113 for(i=1;i<=n;i++){ 114 scanf("%s",ss+1); 115 for(j=1;j<=d;j++){ 116 if(ss[j]=='Y')D.add(f+n+i,f+2*n+j,1); 117 } 118 } 119 printf("%d\n",D.mf(0,f+2*n+d+1)); 120 } 121 return 0; 122 }
View Code
转载于:https://www.cnblogs.com/cenariusxz/p/6598104.html
hdu4292 Food 最大流相关推荐
- stream流对象的理解及使用
我的理解:用stream流式处理数据,将数据用一个一个方法去 . (点,即调用) 得到新的数据结果,可以一步达成. 有多种方式生成 Stream Source: 从 Collection 和数组 Co ...
- 如何判断飞机的年限_技术流带你鉴定前风挡玻璃更换,不再使用日期判断!
这又是一篇关于前风挡玻璃鉴定的文章,我记得在二手车鉴定微信公众号里面已经发布好几篇这样的文章了,当然每篇文章的住重点不同,今天这一篇应该是完结篇,它们在一起能组成一套玻璃更换系列专题课程: 我们回 ...
- SpringCloud Alibaba微服务实战(五) - Sentinel实现限流熔断
什么是Sentinel? 请查看文章:SpringCloud Alibaba微服务实战(一) - 基础环境搭建 构建服务消费者cloud-sentinel进行服务调用 服务创建请查看文章:Spring ...
- 文件流处理流式处理大数据处理
20210315 https://www.yuque.com/7125messi/wydusr/wweetn 42-(重要重要重要)加速pandas(Modin和pandarallel) 重点 htt ...
- javaSE8的流库总结
前言 本篇博客对 java 8 的流库进行一个总结 1. 从迭代到流 在处理集合时,我们通常会迭代遍历它的元素,并在每个元素上执行某项操作,列如假设我们想统计某本书的所有长单词数(单词长度大于10): ...
- CUDA 7流简化并发
CUDA 7流简化并发 异构计算是指有效使用系统中的所有处理器,包括CPU和GPU.为此,应用程序必须在多个处理器上同时执行功能.CUDA应用程序通过在流(按顺序执行的命令序列)中,执行异步命令来管理 ...
- GPU编程和流式多处理器(二)
GPU编程和流式多处理器(二) 2. 整数支持 SM具有32位整数运算的完整补充. • 加法运算符的可选否定加法 • 乘法与乘法加法 • 整数除法 • 逻辑运算 • 条件码操作 • to/from浮点 ...
- GPU编程和流式多处理器
GPU编程和流式多处理器 流式多处理器(SM)是运行CUDA内核的GPU的一部分.本章重点介绍SM的指令集功能. 流式多处理器(SM)是运行我们的CUDA内核的GPU的一部分.每个SM包含以下内容. ...
- Cuda Stream流 分析
Cuda Stream流分析 Stream 一般来说,cuda c并行性表现在下面两个层面上: • Kernel level • Grid level Stream和event简介 Cuda stre ...
最新文章
- 如何在浏览器端爬取信息(只是配置的部分)----设置环境
- 2017年最受欢迎的10个编程挑战网站
- Intger To Roman
- 怎么把计算机改程序,怎样修改程序软件
- Android pm 命令详解
- jdk重启后步行_向后介绍步行以一种新颖的方式来预测未来
- 吉他谱——寂寞是因为思念谁
- memset 和 memcpy 和 memcmp (strncmp遇到\0会中断)
- mysql数据库优化总结 有图 有用
- Redis客户端Redisson+SpringBoot实现的分布式锁案例
- 【Unity】 Unity主题皮肤
- CUDA +cnn安装
- 泰坦尼克号乘客生存情况分析之第二部分特征工程
- java学习笔记参考
- ZXing二维码自定义绘画文字
- Windows 10如何将网络图标放在桌面
- mpvue + vuex搭建小程序详细教程
- 虚幻引擎(3)-第三人称视角
- 系统集成项目管理工程师高频考点(第一章)
- JAVA学习日记每天进步一点点之集合类