博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3281 Dining (最大流)
阅读量:5244 次
发布时间:2019-06-14

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

Dining
Time Limit: 2000MS   Memory Limit: 65536K
     

Description

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 
Fi integers 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 分析 之前做过类似的题了,建图就是将奶牛拆成两个点,左边连食物,右边连饮料,食物和饮料分别连源点和汇点,跑最大流就行了。
#include
#include
#include
#include
using namespace std;//****************************************************//最大流模板Edmonds_Karp算法//初始化:G[][],st,ed//******************************************************const int MAXN = 500;const int INF = 0x3fffffff;int G[MAXN][MAXN];//存边的容量,没有边的初始化为0int path[MAXN],flow[MAXN],st,ed;int n;//点的个数,编号0~n,n包括了源点和汇点queue
q;int bfs(){ int i,t; while(!q.empty()) q.pop();//清空队列 memset(path,-1,sizeof(path));//每次搜索前都把路径初始化成-1 path[st]=0; flow[st]=INF;//源点可以有无穷的流流进 q.push(st); while(!q.empty()){ t=q.front(); q.pop(); if(t==ed) break; for(i=0;i<=n;i++){ if(i!=st&&path[i]==-1&&G[t][i]){ flow[i]=flow[t]

 

 

转载于:https://www.cnblogs.com/wangdongkai/p/5618860.html

你可能感兴趣的文章
FancyCoverFlow
查看>>
教你一分钟实现动态模糊效果
查看>>
C++中explicit的用法
查看>>
java 企业站源码 兼容手机平板PC 响应式 主流SSM框架 freemaker 静态引擎
查看>>
AliOS编译安装MyRocks
查看>>
JS博客
查看>>
Docx转Doc操作(c#)
查看>>
Docker——error pulling image configuration
查看>>
一条简单的 SQL 执行超过 1000ms,纳尼?
查看>>
Python函数(一)之杵臼之交
查看>>
关于将qt作为max插件ui库所遇到的困难
查看>>
如何设置映射网络驱动器的具体步骤和方法
查看>>
ASP.NET WebApi 基于OAuth2.0实现Token签名认证
查看>>
SendMail与Postfix的架构备忘
查看>>
paip.mysql 性能测试 报告 home right
查看>>
Atitit.跨平台预定义函数 魔术方法 魔术函数 钩子函数 api兼容性草案 v2 q216 java c# php js.docx...
查看>>
283. Move Zeroes把零放在最后面
查看>>
我的函数说明风格
查看>>
ssh 简介
查看>>
26.无向网邻接表类
查看>>