链接:

https://vjudge.net/problem/HDU-4292

题意:

  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.

思路:

最大流,建图,模板题.

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL; const int MAXN = 200+10;
const int INF = 1e9; struct Edge
{
int from, to, cap;
};
vector<int> G[MAXN*4];
vector<Edge> edges;
int Dis[MAXN*4];
int Fo, Dr;
int n, f, d, s, t; void Init()
{
for (int i = s;i <= t;i++)
G[i].clear();
edges.clear();
} void AddEdge(int from, int to, int cap)
{
edges.push_back(Edge{from, to, cap});
edges.push_back(Edge{to, from, 0});
G[from].push_back(edges.size()-2);
G[to].push_back(edges.size()-1);
} bool Bfs()
{
memset(Dis, -1, sizeof(Dis));
queue<int> que;
que.push(s);
Dis[s] = 0;
while (!que.empty())
{
int u = que.front();
que.pop();
for (int i = 0;i < G[u].size();i++)
{
Edge &e = edges[G[u][i]];
if (e.cap > 0 && Dis[e.to] == -1)
{
Dis[e.to] = Dis[u]+1;
que.push(e.to);
}
}
}
return Dis[t] != -1;
} int Dfs(int u, int flow)
{
if (u == t)
return flow;
int res = 0;
for (int i = 0;i < G[u].size();i++)
{
Edge &e = edges[G[u][i]];
if (e.cap > 0 && Dis[u]+1 == Dis[e.to])
{
int tmp = Dfs(e.to, min(flow, e.cap));
e.cap -= tmp;
flow -= tmp;
res += tmp;
edges[G[u][i]^1].cap += tmp;
if (flow == 0)
break;
}
}
if (res == 0)
Dis[u] = -1;
return res;
} int MaxFlow()
{
int res = 0;
while (Bfs())
res += Dfs(s, INF);
return res;
} int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
while (cin >> n >> f >> d)
{
s = 0, t = n*2+f+d+1;
Init();
for (int i = 1;i <= f;i++)
{
cin >> Fo;
AddEdge(0, 2*n+i, Fo);
}
for (int i = 1;i <= d;i++)
{
cin >> Dr;
AddEdge(2*n+f+i, t, Dr);
}
for (int i = 1;i <= n;i++)
AddEdge(i*2-1, i*2, 1);
char ok;
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= f;j++)
{
cin >> ok;
if (ok == 'Y')
AddEdge(2*n+j, 2*i-1, 1);
}
}
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= d;j++)
{
cin >> ok;
if (ok == 'Y')
AddEdge(2*i, 2*n+f+j, 1);
}
}
int res = MaxFlow();
cout << res << endl;
} return 0;
}

HDU-4292-Food(最大流,Dinic)的更多相关文章

  1. HDU 4292 Food 最大流

    Food Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. HDU 4292 Food (网络流,最大流)

    HDU 4292 Food (网络流,最大流) Description You, a part-time dining service worker in your college's dining ...

  3. 网络流之最大流Dinic算法模版

    /* 网络流之最大流Dinic算法模版 */ #include <cstring> #include <cstdio> #include <queue> using ...

  4. poj-1459-最大流dinic+链式前向星-isap+bfs+stack

    title: poj-1459-最大流dinic+链式前向星-isap+bfs+stack date: 2018-11-22 20:57:54 tags: acm 刷题 categories: ACM ...

  5. 网络流之最大流Dinic --- poj 1459

    题目链接 Description A power network consists of nodes (power stations, consumers and dispatchers) conne ...

  6. 网络最大流Dinic

    1.什么是网络最大流 形象的来说,网络最大流其实就是这样一个生活化的问题:现在有一个由许多水管组成的水流系统,每一根管道都有自己的最大通过水流限制(流量),超过这个限制水管会爆(你麻麻就会来找你喝茶q ...

  7. HDU 3572 Task Schedule(拆点+最大流dinic)

    Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  8. HDU 4292:Food(最大流)

    http://acm.hdu.edu.cn/showproblem.php?pid=4292 题意:和奶牛一题差不多,只不过每种食物可以有多种. 思路:因为食物多种,所以源点和汇点的容量要改下.还有D ...

  9. (网络流 最大流 Dinic || SAP)Control -- hdu --4289

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4289 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  10. H - Food - hdu 4292(简单最大流)

    题目大意:有N个人,然后有F种食品和D种饮料,每个人都有喜欢的饮料和食品,求出来这些食品最多能满足多少人的需求. 输入描述: 分析:以前是做过类似的题目的,不过输入的信息量比较大,还是使用邻接表的好些 ...

随机推荐

  1. Python 的列表生成器

    列表生成器为创建列表提供了一种简洁的方式. 比如说,我们可以这样实现一个平方数列表 squares=[x**2 for x in range(10)] 或者这样迭代一个字符串来生成列表 >> ...

  2. javaScript 实现倒计时 + 获取网页中的文字

    一.倒计时 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <tit ...

  3. Python学习之协程

    8.8 协程 ​ 我们都知道线程间的任务切换是由操作系统来控制的,而协程的出现,就是为了减少操作系统的开销,由协程来自己控制任务的切换 ​ 协程本质上就是线程.既然能够切换任务,所以线程有两个最基本的 ...

  4. mysql——单表查询——聚合函数——概念

    使用聚合函数查询 group by关键字通常和聚合函数一起使用 .count()函数 count()函数用来统计记录的条数 举例:使用count()函数统计employee表的记录数 select c ...

  5. mybatis返回List<Map>

    mapperl.xml中: <select id="getAmount" parameterType="int" resultType="jav ...

  6. 2019JAVA第十次实验报告

    Java实验报告 班级 计科二班 学号 20188442 姓名 吴怡君 完成时间 2019.11.15 评分等级 实验代码 package Domon9; import java.awt.Font; ...

  7. spring boot-11.全局捕获异常

    1.在Spring boot 中如果发生错误,浏览器访问会默认跳转到Whitelabel Error Page 这个错误页面,如果是客户端访问的话返回JSON格式的错误数据,说明spring boot ...

  8. idea常用快捷键列表

    在使用IntelliJ Idea的时候,使用快捷键是必不可少的.掌握一些常用的快捷键能大大提高我们的开发效率.有些快捷键可以熟练的使用,但是还有另外一些快捷键虽然很好用,但是由于因为没有形成使用习惯或 ...

  9. a++和++a的区别

    a++是先执行表达式后再自增,执行表达式时使用的是a的原值.++a是先自增再执行表达示,执行表达式时使用的是自增后的a.例:int a=0printf("%d",a++); //输 ...

  10. Vue 基础语法入门(转载)

    使用vue.js原文介绍:Vue.js是一个构建数据驱动的web界面库.Vue.js的目标是通过尽可能简单的API实现响应式数据绑定和组合的视图组件.vue.js上手非常简单,先看看几个例子: 例一: ...