H - Food HDU - 4292 网络流
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.
Input There are several test cases.
For each test case, the first line contains three numbers: N,F,D, denoting the number of people, food, and drink.
The second line contains F integers, the ith number of which denotes amount of representative food.
The third line contains D integers, the ith number of which denotes amount of representative drink.
Following is N line, each consisting of a string of length F. e jth character in the ith one of these lines denotes whether people i would accept food j. “Y” for yes and “N” for no.
Following is N line, each consisting of a string of length D. e jth character in the ith one of these lines denotes whether people i would accept drink j. “Y” for yes and “N” for no.
Please process until EOF (End Of File).
Output For each test case, please print a single line with one integer, the maximum number of people to be satisfied.
Sample Input
4 3 3
1 1 1
1 1 1
YYN
NYY
YNY
YNY
YNY
YYN
YYN
NNY
Sample Output
3 题目大意:
这个就是一个牛吃草问题
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 1e5 + ;
const int INF = 0x3f3f3f3f;
struct edge
{
int u, v, c, f;
edge(int u, int v, int c, int f) :u(u), v(v), c(c), f(f) {}
};
vector<edge>e;
vector<int>G[maxn];
int level[maxn];//BFS分层,表示每个点的层数
int iter[maxn];//当前弧优化
int m, s, t;
void init(int n)
{
for (int i = ; i <= n; i++)G[i].clear();
e.clear();
}
void add(int u, int v, int c)
{
e.push_back(edge(u, v, c, ));
e.push_back(edge(v, u, , ));
m = e.size();
G[u].push_back(m - );
G[v].push_back(m - );
}
void BFS(int s)//预处理出level数组
//直接BFS到每个点
{
memset(level, -, sizeof(level));
queue<int>q;
level[s] = ;
q.push(s);
while (!q.empty())
{
int u = q.front();
q.pop();
for (int v = ; v < G[u].size(); v++)
{
edge& now = e[G[u][v]];
if (now.c > now.f && level[now.v] < )
{
level[now.v] = level[u] + ;
q.push(now.v);
}
}
}
}
int dfs(int u, int t, int f)//DFS寻找增广路
{
if (u == t)return f;//已经到达源点,返回流量f
for (int &v = iter[u]; v < G[u].size(); v++)
//这里用iter数组表示每个点目前的弧,这是为了防止在一次寻找增广路的时候,对一些边多次遍历
//在每次找增广路的时候,数组要清空
{
edge &now = e[G[u][v]];
if (now.c - now.f > && level[u] < level[now.v])
//now.c - now.f > 0表示这条路还未满
//level[u] < level[now.v]表示这条路是最短路,一定到达下一层,这就是Dinic算法的思想
{
int d = dfs(now.v, t, min(f, now.c - now.f));
if (d > )
{
now.f += d;//正向边流量加d
e[G[u][v] ^ ].f -= d;
//反向边减d,此处在存储边的时候两条反向边可以通过^操作直接找到
return d;
}
}
}
return ;
}
int Maxflow(int s, int t)
{
int flow = ;
for (;;)
{
BFS(s);
if (level[t] < )return flow;//残余网络中到达不了t,增广路不存在
memset(iter, , sizeof(iter));//清空当前弧数组
int f;//记录增广路的可增加的流量
while ((f = dfs(s, t, INF)) > )
{
flow += f;
}
}
return flow;
} int main()
{
int n, fo, di;
while(scanf("%d%d%d", &n, &fo, &di)!=EOF)
{
init(*n+fo+di+);
s = , t = * n + fo + di + ;
for (int i = ; i <= fo; i++)
{
int num;
scanf("%d", &num);
add(s, i, num);
}
for (int i = ; i <= di; i++)
{
int num;
scanf("%d", &num);
add(i + fo + * n, t, num);
}
for (int i = ; i <= n; i++)
{
add(i + fo, i + n + fo, );
}
for (int i = ; i <= n; i++)
{
char qw[];
scanf("%s", qw);
for (int j = ; j < fo; j++)
{
if (qw[j] == 'Y') add(j + , i + fo, );
}
}
for (int i = ; i <= n; i++)
{
char qw[];
scanf("%s", qw);
for (int j = ; j < di; j++)
{
if (qw[j] == 'Y') add(i + fo + n, j + fo + * n + , );
}
}
int ans = Maxflow(s, t);
printf("%d\n", ans);
}
return ;
}
H - Food HDU - 4292 网络流的更多相关文章
- Food HDU - 4292 网络流 拆点建图
http://acm.hdu.edu.cn/showproblem.php?pid=4292 给一些人想要的食物和饮料,和你拥有的数量,问最多多少人可以同时获得一份食物和一份饮料 写的时候一共用了2种 ...
- H - Food - hdu 4292(简单最大流)
题目大意:有N个人,然后有F种食品和D种饮料,每个人都有喜欢的饮料和食品,求出来这些食品最多能满足多少人的需求. 输入描述: 分析:以前是做过类似的题目的,不过输入的信息量比较大,还是使用邻接表的好些 ...
- HDU 4292 Food (网络流,最大流)
HDU 4292 Food (网络流,最大流) Description You, a part-time dining service worker in your college's dining ...
- HDU 4292Food(网络流的最大流量)
职务地址:HDU 4292 水题. 因为每一个人仅仅能有1份,所以须要拆点限制流量.建图方法为,建一源点与汇点.将食物与源点相连,权值为食物额数量,将饮料与汇点相连,权值为饮料数量..然后将人进行拆点 ...
- 【解题报告】 Leapin' Lizards HDU 2732 网络流
[解题报告] Leapin' Lizards HDU 2732 网络流 题外话 在正式讲这个题目之前我想先说几件事 1. 如果大家要做网络流的题目,我在网上看到一个家伙,他那里列出了一堆网络流的题目, ...
- (网络流)Food -- hdu -- 4292
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4292 Food Time Limit: 2000/1000 MS (Java/Others) Me ...
- hdu 4292 Food 网络流
题目链接 给你f种食物, 以及每种食物的个数, d种饮料, 以及个数, n个人, 以及每个人可以接受的食物种类和饮料种类. 每个人必须得到一种食物和一种饮料. 问最后得到满足的人的个数. 因为一个人只 ...
- HDU 4292:Food(最大流)
http://acm.hdu.edu.cn/showproblem.php?pid=4292 题意:和奶牛一题差不多,只不过每种食物可以有多种. 思路:因为食物多种,所以源点和汇点的容量要改下.还有D ...
- hdu 4280 网络流
裸的网络流,递归的dinic会爆栈,在第一行加一句就行了 #pragma comment(linker, "/STACK:1024000000,1024000000") #incl ...
随机推荐
- cmake cpack 安装打包程序
//set(CPACK_GENERATOR "TGZ") 7Z(.7z) 7Zzip(.7z) TBZ2(tar.bz2) TGZ(.tar.gz) TXZ(.tar.xz) TZ ...
- mysql 主键和默认 设为索引的规则
一.mysql 表中如果是单主键的话,那这个主键也会被 系统默认建为 索引 二.mysql 表中如果是复合主键的话,那系统会遵循左对齐原则,即如复合主键 a 和 b字段和c字段..., 默认建的主键索 ...
- 跳转语句break与continue的使用环境
break:改变程序控制流 常用于do-while.while.for .switch循环中,终止某个循环,程序跳转到循环块外的下一条语句 continue:跳出本次循环,进入下一次循环
- N皇后问题 回溯非递归算法 C++实现2
运行结果 代码如下 #include <bits/stdc++.h> using namespace std; ; const char *LINE32 = "--------- ...
- python干货:5种反扒机制的解决方法
前言 反爬虫是网站为了维护自己的核心安全而采取的抑制爬虫的手段,反爬虫的手段有很多种,一般情况下除了百度等网站,反扒机制会常常更新以外.为了保持网站运行的高效,网站采取的反扒机制并不是太多,今天分享几 ...
- 常用App用户体验找茬
冯晓云: 哔哩哔哩手机客户端:视频播放只允许横屏全屏:还有长视频的“5分钟诅咒”,遇到网速不好的时候是个大写的悲剧: 必应词典UWP版本:主页新闻链接跳转后,一些页面不支持划词取译,当然本身各个页面也 ...
- Problem F Free Weights
二分答案. 思路:对于二分给定的mid,即当前允许移动的最大重量,我们可以把小于改重量的标记一下,然后把没有标记的按照顺序放到另一个数组,然后判断是否满足两两相同. #include<bits/ ...
- 格式化启动盘win10
我这个(U盘)磁盘被分成了两个区,不能直接格式化 第一步: 第二步: 删除完了之后,选择格式化,ok. 说明:格式化时要选择系统. 常规NTFS 缺点:老设备,比如打印机,监控机识别不了. FAT系 ...
- 5. react父子组件
1. 父组件如何获取子组件的方法以及属性? 1.)父组件: render( ){ console.log( this.refs.getmethod ): return ( <div> &l ...
- Git 创建远程仓库并克隆到本地,创建本地仓库并推送到远程仓库
配置用户信息 配置的是你个人的用户名称和电子邮件地址.这两条配置很重要,每次 Git 提交时都会引用这两条信息,说明是谁提交了更新,会随更新内容一起被永久纳入历史记录 git config --glo ...