博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ3281 Dining
阅读量:6253 次
发布时间:2019-06-22

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

Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will consume no others.

Farmer John has cooked fabulous meals for his cows, but he forgot to check his menu against their preferences. Although he might not be able to stuff everybody, he wants to give a complete meal of both food and drink to as many cows as possible.

Farmer John has cooked F (1 ≤ F ≤ 100) types of foods and prepared D (1 ≤ D ≤ 100) types of drinks. Each of his N (1 ≤ N ≤ 100) cows has decided whether she is willing to eat a particular food or drink a particular drink. Farmer John must assign a food type and a drink type to each cow to maximize the number of cows who get both.

Each dish or drink can only be consumed by one cow (i.e., once food type 2 is assigned to a cow, no other cow can be assigned food type 2).

Input

Line 1: Three space-separated integers: 
N
F, and 
D 
Lines 2.. 
N+1: Each line 
i starts with a two integers 
Fi and 
Di, the number of dishes that cow 
i likes and the number of drinks that cow 
i likes. The next 
Fiintegers denote the dishes that cow 
i will eat, and the 
Di integers following that denote the drinks that cow 
i will drink.

Output

Line 1: A single integer that is the maximum number of cows that can be fed both food and drink that conform to their wishes

Sample Input

4 3 32 2 1 2 3 12 2 2 3 1 22 2 1 3 1 22 1 1 3 3

Sample Output

3

Hint

One way to satisfy three cows is: 
Cow 1: no meal 
Cow 2: Food #2, Drink #2 
Cow 3: Food #1, Drink #1 
Cow 4: Food #3, Drink #3 
The pigeon-hole principle tells us we can do no better since there are only three kinds of food or drink. Other test data sets are more challenging, of course.
 
 
题意:n头奶牛,f种食物,d种饮料。每种食物,饮料只有一份。每头奶牛需要一份食物和饮料,求满足奶牛需求的最大数量。
 
建图:食物与源点相连,流量为1,奶牛拆开,控制流量为1,然后奶牛与水连接,流量为1。跑最大流即可
1 #include
2 #include
3 #include
4 #include
5 using namespace std; 6 using namespace std; 7 8 const int maxn=100010; 9 const int maxm=400010; 10 const int inf=0x3f3f3f3f; 11 struct Edge{ 12 int to,next,cap,flow,cost; 13 }edge[maxm]; 14 15 int tol; 16 int head[maxn]; 17 int gap[maxn],dep[maxn],cur[maxn]; 18 void init() { 19 tol=0; 20 memset(head,-1,sizeof(head)); 21 } 22 void addedge(int u,int v,int w,int rw=0) { 23 edge[tol].to=v;edge[tol].cap=w;edge[tol].flow=0; 24 edge[tol].next=head[u];head[u]=tol++; 25 edge[tol].to=u;edge[tol].cap=rw;edge[tol].flow=0; 26 edge[tol].next=head[v];head[v]=tol++; 27 } 28 29 int Q[maxn]; 30 void bfs(int start,int end) { 31 memset(dep,-1,sizeof(dep)); 32 memset(gap,0,sizeof(gap)); 33 gap[0]=1; 34 int front=0,rear=0; 35 dep[end]=0; 36 Q[rear++]=end; 37 while(front!=rear) { 38 int u=Q[front++]; 39 for(int i=head[u];i!=-1;i=edge[i].next) { 40 int v=edge[i].to; 41 if(dep[v]!=-1) continue; 42 Q[rear++]=v; 43 dep[v]=dep[u]+1; 44 gap[dep[v]]++; 45 } 46 } 47 } 48 49 int S[maxn]; 50 int sap(int start,int end,int n) { 51 bfs(start,end); 52 memcpy(cur,head,sizeof(head)); 53 int top=0; 54 int u=start; 55 int ans=0; 56 while(dep[start]
edge[S[i]].cap-edge[S[i]].flow) { 62 minn=edge[S[i]].cap-edge[S[i]].flow; 63 inser=i; 64 } 65 } 66 for(int i=0;i

 

 

转载于:https://www.cnblogs.com/ACMerszl/p/10871413.html

你可能感兴趣的文章
我的友情链接
查看>>
如何更好地对齐分区??
查看>>
使用Python从rds上下载mysql备份文件
查看>>
react native组件的创建
查看>>
批量删除文件
查看>>
Linux网络管理
查看>>
iOS JSPatch 热修复使用
查看>>
某二级行机房搬迁
查看>>
基于MVC+EasyUI的Web开发框架经验总结(4)--使用图表控件Highcharts
查看>>
vs2015 xamarin 添加智能感知
查看>>
call to member function bind_param() on boolean...........
查看>>
刘启成_补充知识:awk:报告生成器
查看>>
Linux LVM逻辑卷配置过程详解
查看>>
【技术分享】VSAN如何处理磁盘或主机故障
查看>>
OS快捷键
查看>>
linux内核中Kconfig和Makefile 详解
查看>>
ASP.NET 使用List<T>.Remove 不生效
查看>>
Nginx的第三方模块ngx-fancyindex安装
查看>>
TCP有限状态机
查看>>
XenServer常用Debug问题的命令介绍
查看>>