(网络流)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 ...
随机推荐
- GNU Radio: 射频子板
本文简要介绍 USRP 配套的子板参数信息. 射频子板WBX-40 性能特点 频率覆盖:50 MHz – 2.2GHz 最大信号处理带宽:40MHz 行为描述 WBX-40提供高宽带收发器,可提供高达 ...
- SpringBoot2.0 url中出现特殊符号「带括号{}'"等等」时会抛出400错误
访问 http://127.0.0.1:8080/api?method=taxiong.goods.list¶ms={"page":1,"pageSize ...
- SouthidcEditor编辑器如何支持上传png图片
SouthidcEditor编辑器如何支持上传png图片? asp网站一般都是用的南方数据SouthidcEditor编辑器,可是这个编辑器上传图片功能不能上传png类型的图片,那怎么办?我(红蜘蛛网 ...
- 如何判断两个IP地址是不是在同一个网段
要判断两个IP地址是不是在同一个网段,就将它们的IP地址分别与子网掩码做与运算,得到的结果一网络号,如果网络号相同,就在同一子网,否则,不在同一子网. 例:假定选择了子网掩码255.255.254. ...
- Centos生成SSL证书的步骤
1.yum install openssl安装openssl组件2.生成KEY的流程步骤如下 1. 创建根证书密钥文件(自己做CA)root.key: openssl genrsa -out root ...
- 如何制作行政区划矢量图(shp格式)
详细图文ArcGIS10.2破解版教程地址:http://jingyan.baidu.com/article/e73e26c0cb5c1324adb6a791.html 有时候想要一张shp格式的地方 ...
- Django ORM-01
What is ORM Django ? ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术. ...
- CentOS 6.7 编译PHP7 make时出现错误:undefined reference to `libiconv_close’
编辑Makefile文件,找到变量EXTRA_LIBS,并在末尾添上-liconv EXTRA_LIBS = -lcrypt -lz -lexslt -lcrypt -lrt -lmcrypt -ll ...
- Linux常用命令之-grep
简介 grep全称Global Regular Expression Print是一种强大的文本搜索工具,它能使用给定的正则表达式按行搜索文本输出,文件,目录等,统计并输出匹配的信息,grep在文本查 ...
- Space-vim的.spacevim配置备份
安装 windows安装 配置 在C盘的用户目录下,有一个'.spacevim'的文件,可以修改你要的配置 " Let Vim and NeoVim shares the same plug ...