(网络流)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 ...
随机推荐
- Quick guide for converting from JAGS or BUGS to NIMBLE
Converting to NIMBLE from JAGS, OpenBUGS or WinBUGS NIMBLE is a hierarchical modeling package that u ...
- 关于layoutparam 请铭记。。。。
//rl_pager 是RelativeLayout findViewById(R.id.rl_pager).setLayoutParams(new RelativeLayout.LayoutPara ...
- selenium笔记2017
1,from time import sleep(先引入关键词) sleep(5) (就可以使用这个命令了) 可以停止页面5秒 1-1. 等待页面元素出现的时间(即没出现时,等待元素出现) ...
- Go语言并发编程总结
转自:http://blog.csdn.net/yue7603835/article/details/44309409 Golang :不要通过共享内存来通信,而应该通过通信来共享内存.这句风靡在Go ...
- 部分流媒体协议及流媒体开发框架vitamio
流媒体协议部分RTP.RTCP.RTSP.MMS.HLS.HTTP progressive streaming 流媒体协议:(RTP.RTCP.RTSP.MMS.HLS.HTTP progress ...
- How to create a site with AJAX enabled in MVC framework.
How to create a site with AJAX enabled in MVC framework. The Project illustrates how to create a web ...
- MyEclipse8.6启动后提示内存不足的解决方案(亲测,完美解决)
转自:http://www.bubuko.com/infodetail-1625857.html 最近可能由于公司项目大了,启动MyEclipse后经常提示内存不足的警告框,如下: 其实点击close ...
- sudo免密码
很多都是修改/etc/sudoers权限为740再加上一句 ALL=NOPASSWD:ALL 或者加一句 yourname ALL=(ALL) NOPASSWD: ALL 然后权限改回440 先说第一 ...
- 为阿里云ECS服务器二级域名绑定tomcat子目录,实现一个IP多个二级域名
摘要:前几天租了阿里云ECS服务器,选择的Windows系统,并在服务器上部署了tomcat服务器,随后我又买了一个域名,可一个域名只能指向一个IP地址,包括二级域名也只能指向一个IP地址,并不能指向 ...
- Jboss:The LogManager was not properly installed (you must set the "java.util.logging.manager" system prop
可能是jboss的服务器版本选择不对 ,比如我本地的Jboss服务器版本是 jboss-as-web-7.0.2.Final,选择的服务器版本是JBOOS V7.1 Runtime ,就会报上面 ...