(网络流)Food -- hdu -- 4292
链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4292
Food
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4060 Accepted Submission(s): 1359
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.
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).
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <queue>
#include <algorithm>
using namespace std; #define N 1000
#define INF 0x3f3f3f3f int G[N][N], Layer[N]; bool BFS(int S, int E)
{
queue<int>Q;
Q.push(S); memset(Layer, , sizeof(Layer));
Layer[S] = ; while(Q.size())
{
int u = Q.front(); Q.pop(); if(u==E) return true; for(int i=; i<=E; i++)
{
if(Layer[i]== && G[u][i])
{
Layer[i]=Layer[u]+;
Q.push(i);
}
}
}
return false;
} int DFS(int u, int MaxFlow, int E)
{
if(u==E) return MaxFlow; int uflow=;
for(int i=; i<=E; i++)
{
if(G[u][i] && Layer[u]+==Layer[i])
{
int flow = min(G[u][i], MaxFlow-uflow);
flow = DFS(i, flow, E); G[u][i] -= flow;
G[i][u] += flow;
uflow += flow; if(uflow==MaxFlow) break;
}
} if(uflow==) Layer[u] = ; return uflow;
} int Dinic(int S, int E)
{
int ans = ; while(BFS(S, E))
ans += DFS(S, INF, E); return ans;
} int main()
{
int n, F, D; while(scanf("%d%d%d", &n, &F, &D)!=EOF)
{
int i, j, a[N], b[N];
char s[N]; memset(G, , sizeof(G)); for(i=; i<=F; i++)
scanf("%d", &a[i]);
for(i=; i<=D; i++)
scanf("%d", &b[i]); for(i=; i<=n; i++)
G[i][i+n] = ;
for(i=n*+; i<=n*+F; i++)
G[][i] = a[i-*n];
for(i=n*+F+; i<=n*+F+D; i++)
G[i][n*+F+D+] = b[i-n*-F]; for(i=; i<=n; i++)
{
scanf("%s", s); for(j=; j<F; j++)
if(s[j]=='Y')
G[n*+j+][i] = ;
} for(i=; i<=n; i++)
{
scanf("%s", s); for(j=; j<=D; j++)
if(s[j]=='Y')
G[i+n][*n+F+j+] = ;
} printf("%d\n", Dinic(, *n+F+D+));
}
return ;
}
(网络流)Food -- hdu -- 4292的更多相关文章
- HDU 4292 Food (网络流,最大流)
HDU 4292 Food (网络流,最大流) Description You, a part-time dining service worker in your college's dining ...
- Food HDU - 4292 网络流 拆点建图
http://acm.hdu.edu.cn/showproblem.php?pid=4292 给一些人想要的食物和饮料,和你拥有的数量,问最多多少人可以同时获得一份食物和一份饮料 写的时候一共用了2种 ...
- hdu 4292 Food 网络流
题目链接 给你f种食物, 以及每种食物的个数, d种饮料, 以及个数, n个人, 以及每个人可以接受的食物种类和饮料种类. 每个人必须得到一种食物和一种饮料. 问最后得到满足的人的个数. 因为一个人只 ...
- H - Food HDU - 4292 网络流
题目 You, a part-time dining service worker in your college’s dining hall, are now confused with a n ...
- HDU 4292:Food(最大流)
http://acm.hdu.edu.cn/showproblem.php?pid=4292 题意:和奶牛一题差不多,只不过每种食物可以有多种. 思路:因为食物多种,所以源点和汇点的容量要改下.还有D ...
- 网络流强化-HDU 3338-上下界限制最大流
题意是: 一种特殊的数独游戏,白色的方格给我们填1-9的数,有些带数字的黑色方格,右上角的数字代表从他开始往右一直到边界或者另外一个黑格子,中间经过的白格子的数字之和要等于这个数字:左下角的也是一样的 ...
- hdu 4292 最大流 水题
很裸的一道最大流 格式懒得排了,注意把人拆成两份,一份连接食物,一份连接饮料 4 3 3 //4个人,3种食物,3种饮料 1 1 1 //食物每种分别为1 1 1 1 //饮料每种数目分别为1 YYN ...
- HDU 4292 Food 最大流
Food Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 4292 Food
Food Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
随机推荐
- Tomcat 7 的七大新特性(更容易将Tomcat内嵌到应用去中去 )
Tomcat的7引入了许多新功能,并对现有功能进行了增强.很多文章列出了Tomcat 7的新功能,但大多数并没有详细解释它们,或指出它们的不足,或提供代码示例.本文将明确描述TOMCAT 7中七个最显 ...
- SSH&SFTP服务分离+家目录锁定
Step 1 在root用户下创建维护账号的家目录,此处以创建userftp帐号的家目录为例. mkdir -p /chroot/home/user Step 2 在root用户根目录下执行以下命令设 ...
- hadoop自带TestDFSIO学习
hadoop系统中,包含了很多测试工具包,如测试mapreduce系统读写文件系统,有testDFSIO工具 首先安装好hadoop,配置好环境变量 进入share目录下的mapreduce目录下面, ...
- 好记性不如烂笔头-linux学习笔记4apache相关知识
apache 启动有2种模式 1是prefork模式,每个进程对应一个线程,如果是比较稳定的平台,那么prefork模式是worker模式 比较好,效率高,但是吃的内存比较大. 2 如果是高负载高并发 ...
- String(byte[] bytes, Charset charset) 和 getBytes() 使用
转自:https://techbirds.iteye.com/blog/1855960 @Test public void testBytes(){ //字节数 //中文:ISO:1 GBK:2 UT ...
- DB2 数据类型转换
db2数据类型转换: 1.CAST() CAST (<expression> AS <data_ type>[ length ]) 2.CONVERT() CONVERT (& ...
- How to run eclipse in clean mode? and what happens if we do so?
What it does: if set to "true", any cached data used by the OSGi framework and eclipse run ...
- CDN理解<转>
CDN则是更高级的手段.CDN到底如何工作的呢,让我们来大概了解一下! CDN的基础百科资料也很多了,我也稍等提一下.CDN,Content Distribute Network,即:内容分发网络. ...
- 7.25 7figting!
TEXT 82 Proton 马来西亚宝腾汽车 A fork in the road 何去何从?(陈继龙编译) Nov 30th 2006 | HONG KONG From The Economist ...
- 南京大学发布无序列限制的DNA编辑新工具(转自生物通)
编辑推荐: 内切酶经过改造可以成为强大的DNA编辑工具,比如ZFN.TALEN.风头正劲的CRISPR–Cas系统和充满争议的NgAgo技术.不过这些技术都是通过序列识别来实现靶向切割的,会受到序列偏 ...