poj 3281 Dining (Dinic)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 22572 | Accepted: 10015 |
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
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
Sample Input
4 3 3
2 2 1 2 3 1
2 2 2 3 1 2
2 2 1 3 1 2
2 1 1 3 3
Sample Output
3
C/C++:
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
const int my_max = ; int my_map[my_max][my_max], my_cow, my_food, my_drink, my_source,
my_sink, n, my_dis[my_max]; int my_dfs(int step, int ans)
{
if (step == my_sink) return ans; int temp = ans;
for (int i = ; i < n && temp; ++ i)
{
if (my_dis[i] + == my_dis[step] && my_map[step][i])
{
int t = my_dfs(i, min(ans, my_map[step][i]));
ans -= t;
my_map[step][i] -= t;
my_map[i][step] += t;
}
}
return temp - ans;
} bool my_bfs()
{
memset(my_dis, -, sizeof(my_dis));
my_dis[my_sink] = ;
queue <int> Q;
Q.push(my_sink);
while (!Q.empty())
{
int my_temp = Q.front();
for (int i = ; i < n; ++ i)
{
if (my_dis[i] == - && my_map[i][my_temp])
{
my_dis[i] = my_dis[my_temp] + ;
Q.push(i);
}
}
if (my_temp == my_source) return true;
Q.pop();
}
return false;
} int my_dinic()
{
int my_max_flow = ;
while (my_bfs())
my_max_flow += my_dfs(my_source, INF); return my_max_flow;
} int main()
{
while (~scanf("%d%d%d", &my_cow, &my_food, &my_drink))
{
my_source = , my_sink = my_food + *my_cow + my_drink;
for (int i = ; i <= my_food; ++ i) my_map[my_source][i] = ;
for (int i = ; i <= my_cow; ++ i) my_map[my_food + i][my_food + my_cow + i] = ;
for (int i = ; i <= my_drink; ++ i) my_map[my_food + *my_cow + i][my_sink] = ; for (int i = ; i <= my_cow; ++ i)
{
int my_food_num, my_drink_num;
scanf("%d%d", &my_food_num, &my_drink_num);
while (my_food_num --)
{
int my_temp;
scanf("%d", &my_temp);
my_map[my_temp][my_food + i] = ;
}
while (my_drink_num --)
{
int my_temp;
scanf("%d", &my_temp);
my_map[my_food + my_cow + i][my_food + * my_cow + my_temp] = ;
}
} n = my_sink + ;
printf("%d\n", my_dinic());
}
return ;
}
poj 3281 Dining (Dinic)的更多相关文章
- POJ 3281 Dining (网络流)
POJ 3281 Dining (网络流) Description Cows are such finicky eaters. Each cow has a preference for certai ...
- POJ 3281 Dining(最大流)
POJ 3281 Dining id=3281" target="_blank" style="">题目链接 题意:n个牛.每一个牛有一些喜欢的 ...
- POJ 3281 网络流dinic算法
B - Dining Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit S ...
- poj 3281 Dining 网络流-最大流-建图的题
题意很简单:JOHN是一个农场主养了一些奶牛,神奇的是这些个奶牛有不同的品味,只喜欢吃某些食物,喝某些饮料,傻傻的John做了很多食物和饮料,但她不知道可以最多喂饱多少牛,(喂饱当然是有吃有喝才会饱) ...
- POJ 3281 Dining(最大流+拆点)
题目链接:http://poj.org/problem?id=3281 题目大意:农夫为他的 N (1 ≤ N ≤ 100) 牛准备了 F (1 ≤ F ≤ 100)种食物和 D (1 ≤ D ≤ 1 ...
- POJ 3281 Dining(最大流)
http://poj.org/problem?id=3281 题意: 有n头牛,F种食物和D种饮料,每头牛都有自己喜欢的食物和饮料,每种食物和饮料只能给一头牛,每头牛需要1食物和1饮料.问最多能满足几 ...
- POJ 3281 Dining(网络流拆点)
[题目链接] http://poj.org/problem?id=3281 [题目大意] 给出一些食物,一些饮料,每头牛只喜欢一些种类的食物和饮料, 但是每头牛最多只能得到一种饮料和食物,问可以最多满 ...
- poj 3281 Dining (最大网络流)
题目链接: http://poj.org/problem?id=3281 题目大意: 有n头牛,f种食物,d种饮料,第i头牛喜欢fi种食物和di种饮料,每种食物或者饮料被一头牛选中后,就不能被其他的牛 ...
- POJ 3281 Dining
Dining Description Cows are such finicky eaters. Each cow has a preference for certain foods and dri ...
随机推荐
- Cocos2d-x 学习笔记(11.3) JumpBy JumpTo
1. JumpBy JumpTo JumpBy,边跳边平移,不只做垂直向上的抛物动作,同时还在向终点平移.JumpTo是JumpBy的子类. 1.1 成员变量 create方法 JumpBy: Vec ...
- java集合之linkedList链表基础
LinkedList链表: List接口的链接列表实现.允许存储所有元素(包含null).使用频繁增删元素. linkedList方法: void addFirst(E e) 指定元素插入列表的开头 ...
- std::tuple
tuple,元组类型.头文件<tuple>,tuple是一个固定大小的不同类型(异质,heterogeneous)值的集合(这一点是tuple与其他常规STL容器的最大不同,即它可以同时存 ...
- selenium-模块概述(1)
Selenium是一个用于Web应用程序自动化测试工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样. 1.目录结构如下: D:\soft\python36\Lib\site-pa ...
- Rsync服务常见问题
转---Rsync 故障排查整理 Rsync服务常见问题汇总讲解: 1. 客户端的错误现象:No route to host rsync服务端开启的iptables**防火墙** [root@nfs0 ...
- 小程序预览pdf文件
有个业务需求,需要在小程序查看客户已开的发票 发票地址: https://www.chinaeinv.com/p.jspa?cxxxxxxxxxxxx 刚开始是想利用webview当作外链进行跳转访问 ...
- lnmp安装mysql
lnmp安装mysql 下载lnmp wget http://soft.vpser.net/lnmp/lnmp1.6.tar.gz 解压 tar ‐xf lnmp1..tar.gz 安装数据库 ./i ...
- element ui实现手动上传文件,且只能上传单个文件,并能覆盖上传。
element ui提供了成熟的组件场景,但实际工作中难免会遇到认(sha)真(diao)的产品.比如,最近遇到的,要求实现手动上传特定格式文件(用户点击“上传文件”按钮,确定之后,只是单纯选择了文件 ...
- hexo博客yili主题个性化自定义教程(1) ——借鉴中学习,初认yili主题
文章转载于:hexo博客yili主题个性化自定义教程(1) --借鉴中学习,初认yili主题 这个博客跌跌撞撞也弄了好多天了,由于Next主题不知道什么情况,被我玩坏了.所以换了一个主题. 大名鼎鼎的 ...
- Java基础(三十六)日期和时间
1.Date类 (1)无参数构造方法创建的对象可以获取本机当前时间 (2)有参数构造方法创建的对象表示举例计算机系统自身时间的距离为给定的参数 Date date = new Date(); // 当 ...