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. 

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

题意:

有一些个数有限的  不同种类的糖果 和 一些不同种类的饮料 , 每个人的口味不同,所以可以选择任意的糖果和饮料 , 每个都只选一个

求能满足最多的人的数量

解析:

建立超级源点s和超级汇点t  把s和糖果连在一起,边权为糖果的数量,  t和饮料连载一其,边权为饮料的数量, 然后把每一个人拆成两个点 其中边权为1

人和糖果、饮料 都建立边 边权为INF;

代码如下:

Dinic + 当前弧优化

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <cmath>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn =, INF = 0x7fffffff;
int cnt = , s, t;
int head[maxn], d[maxn], cur[maxn];
char str[];
struct node{
int u, v, c, next;
}Node[maxn*]; void add_(int u, int v, int c)
{
Node[cnt].u = u;
Node[cnt].v = v;
Node[cnt].c = c;
Node[cnt].next = head[u];
head[u] = cnt++;
} void add(int u,int v,int c)
{
add_(u,v,c);
add_(v,u,);
} bool bfs()
{
queue<int> Q;
mem(d,);
Q.push(s);
d[s] = ;
while(!Q.empty())
{
int u = Q.front(); Q.pop();
for(int i=head[u]; i!=-; i=Node[i].next)
{
node e = Node[i];
if(!d[e.v] && e.c > )
{
d[e.v] = d[e.u] + ;
// cout<< e.v << " " << d[e.v] <<endl;
Q.push(e.v);
if(e.v == t) return ;
}
}
}
// cout<< d[t] <<endl;
return d[t] != ;
} int dfs(int u,int cap)
{
if(u == t || cap == )
return cap;
int ret = ;
for(int &i=cur[u]; i!=-; i=Node[i].next)
{
node e = Node[i];
if(d[e.v] == d[e.u] + && e.c > )
{
int V = dfs(e.v, min(cap, e.c));
Node[i].c -= V;
Node[i^].c += V;
cap -= V;
ret += V;
if(cap == ) break;
}
}
if(cap > ) d[u] = -;
return ret;
} int Dinic()
{
int ans = ;
while(bfs())
{
memcpy(cur,head,sizeof(head));
ans += dfs(s,INF);
}
return ans;
}
int main()
{
int n, f, d;
while(~scanf("%d%d%d",&n,&f,&d))
{
cnt = ;
mem(head,-);
int temp;
s = , t = f+d+n+n+;
for(int i=; i<=f; i++)
{
scanf("%d",&temp);
add(s,i,temp);
}
for(int i=; i<=d; i++)
{
scanf("%d",&temp);
add(f+i,t,temp);
}
for(int i=; i<=n; i++)
{
scanf("%s",str);
for(int j=; j<f; j++)
{
if(str[j] == 'Y'){
add(j+,f+d+i,INF);
}
}
}
for(int i=; i<=n; i++)
add(f+d+i, f+d+n+i,);
for(int i=; i<=n; i++)
{
scanf("%s",str);
for(int j=; j<d; j++)
{
if(str[j] == 'Y')
add(f+d+n+i,f+j+,INF);
}
}
cout<< Dinic() <<endl;
} return ;
}

Food HDU - 4292 (结点容量 拆点) Dinic的更多相关文章

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

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

  2. poj-3436.ACM Computer Factory(最大流 + 多源多汇 + 结点容量 + 路径打印 + 流量统计)

    ACM Computer Factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10940   Accepted:  ...

  3. Food HDU - 4292 网络流 拆点建图

    http://acm.hdu.edu.cn/showproblem.php?pid=4292 给一些人想要的食物和饮料,和你拥有的数量,问最多多少人可以同时获得一份食物和一份饮料 写的时候一共用了2种 ...

  4. UVA1658 Admiral 拆点法解决结点容量(路径不能有公共点,容量为1的时候) 最小费用最大流

    /** 题目:UVA1658 Admiral 链接:https://vjudge.net/problem/UVA-1658 题意:lrj入门经典P375 求从s到t的两条不相交(除了s和t外,没有公共 ...

  5. HDU 4292 Food (拆点最大流)

    题意:N个人,F种食物,D种饮料,给定每种食物和饮料的量.每个人有自己喜欢的食物和饮料,如果得到自己喜欢的食物和饮料才能得到满足.求最大满足的人数. 分析:如果只是简单地N个人选择F种食物的话可以用二 ...

  6. HDU 4292:Food(最大流)

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

  7. HDU 3820 Golden Eggs (SAP | Dinic)

    Golden Eggs Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. HDU 4292 Food (建图思维 + 最大流)

    (点击此处查看原题) 题目分析 题意:某个餐馆出售f种食物,d种饮料,其中,第i种食物有fi份,第i种饮料有di份:此时有n个人来餐馆吃饭,这n个人必须有一份食物和一份饮料才会留下来吃饭,否则,他将离 ...

  9. (网络流)Food -- hdu -- 4292

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4292 Food Time Limit: 2000/1000 MS (Java/Others)    Me ...

随机推荐

  1. linux中yum与rpm区别

    一.源代码形式 1.      绝大多数开源软件都是直接以原码形式发布的 2.      源代码一般会被打成.tar.gz的归档压缩文件 3.      源代码需要编译成为二进制形式之后才能够运行使用 ...

  2. Luogu1979 NOIP2013D2T3 华容道 搜索、最短路

    题目传送门 题意:给出一个$N \times M$的棋盘,棋盘上有一些块可以移动,有一些块无法移动.$Q$次询问,每一次询问给出三个块$a,b,c$,将$a$块变为空格,空格旁边可移动的块可以与空格交 ...

  3. odoo在底部显示指定字段合计和汇总时显示合计

    1.odoo的tree视图底部显示合计 tree 视图,底部显示指定字段合计数 ,视图中字段定义上在sum,取自sale.view_order_tree 销售订单 tree 视图 <field ...

  4. C# 深浅复制 MemberwiseClone

    学无止境,精益求精 十年河东,十年河西,莫欺少年穷 学历代表你的过去,能力代表你的现在,学习代表你的将来 最近拜读了大话设计模式:原型模式,该模式主要应用C# 深浅复制来实现的!关于深浅复制大家可参考 ...

  5. 商场促销-策略模式(和简单工厂模式很像的哇) C#

    还是那几句话: 学无止境,精益求精 十年河东,十年河西,莫欺少年穷 学历代表你的过去,能力代表你的现在,学习代表你的将来 废话不多说,直接进入正题: 首先按照大话设计模式的解释,在这里也总结下策略模式 ...

  6. Centos7 -- glibc 升级失败、意外删除、故意删除后的处理方法

    第一部分:测试(如果不是想测试效果,可以直接跳到第三部分) 鉴于不久前 glibc-2.29 升级失败导致一系列的工具无法正常使用,‘’ 本着研究精神的我决定删除 glibc及其库文件 ,测试影响范围 ...

  7. [SHOI2008]cactus仙人掌图[圆方树+树dp]

    题意 求仙人掌的直径(相距最远的两个点的距离). \(n\le 5\times 10^4​\) 分析 建立圆方树,讨论答案路径的 lca 在圆点还是方点. 利用树形 dp 求出每个圆点到 不同子树内圆 ...

  8. .NET持续集成与自动化部署之路第三篇——测试环境到生产环境的一键部署策略(Windows)

    Jenkins测试环境到生产环境的一键部署策略(Windows) 一.前言     前面我们已经初步实现了开发集成环境.测试环境的持续集成(自动化构建.自动化测试.自动化部署).但生产环境自动化部署迟 ...

  9. Openstack部署踩坑

    第一周: 使用kola部署Openstack,vip_address有问题,双网上也不行,就是部署不了,但all-in-one却可以,可是节点不会加. 第二周: 使用Packstack部署Openst ...

  10. linux-IO重定向-文本流重定向

    输出重定向的追加和覆盖 标准输出就这两种: 覆盖和追加 >> 是重定向操作符 1 是 命令的文件描述符 重定向操作符合文件描述符之间不能存在空白符 否则1会被当做是文件被读取 将正确和错误 ...