(网络流)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 ...
随机推荐
- HttpHelp 请求帮助类
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...
- C#:进程、线程、应用程序域(AppDomain)与上下文分析
进程 进程是操作系统用于隔离众多正在运行的应用程序的机制.在.Net之前,每一个应用程序被加载到单独的进程中,并为该进程指定私有的虚拟内存.进程不能直接访问物理内存,操作系统通过其它的处理把这 ...
- linux svn soeasy
http://blog.163.com/longsu2010@yeah/blog/static/173612348201202114212933/
- Bootstrap-Plugin:滚动监听(Scrollspy)插件
ylbtech-Bootstrap-Plugin:滚动监听(Scrollspy)插件 1.返回顶部 1. Bootstrap 滚动监听(Scrollspy)插件 滚动监听(Scrollspy)插件,即 ...
- [html]CSS 小贴士
CSS 中用四个伪类来定义链接的样式,分别是:a:link.a:visited.a:hover 和 a : active,例如: a:link{font-weight : bold ;text-dec ...
- RTNETLINK answers: File exists
问题: 重启网络时报错如下 >>/etc/init.d/network start RTNETLINK answers: File exists 分析: /etc/init.d/netwo ...
- 小程序本作用域下怎么调用全局js
本地wxml文件 <view>app版本:{{version}}</view> 本地js文件 var app; Page({data:{ }, onLoad:function( ...
- 关于rand 与 randn
rand:0-1均匀分布.均值m=(a+b)/2; 方差=(b-a).^2/12; randn:0均值,方差1. 只有当rand和randn生成较大的数据时,均值和方差才会成立.比如N&g ...
- Oracle安装盘空间不足,对.DBF文件进行迁移
一. select * from dba_data_files 使用该条语句可以查看当前库中有多少表空间并且DBF文件的存储位置 二. 找到对应的dbf文件,将该文件复制到你需要移动的位置 三. 开始 ...
- canvas和svg的区别
讨论关于canvas和svg的区别.首先canvas是html5提供的新元素<canvas>,而svg存在的历史要比canvas久远,已经有十几年了.svg并不是html5专有的标签,最初 ...