hdu 4292 Food 网络流
给你f种食物, 以及每种食物的个数, d种饮料, 以及个数, n个人, 以及每个人可以接受的食物种类和饮料种类。 每个人必须得到一种食物和一种饮料。 问最后得到满足的人的个数。
因为一个人只能得到一种食物, 所以把人拆成两个点, 之间连一条权值为1的边。 建一个源点s, 汇点t, 每种食物向源点连边, 权值为食物的个数, 饮料向汇点连边, 权值为个数。 如果一个人可以接受某种饮料, u'就向饮料连一条权值为1的边; 如果一个人可以接受某种食物, 食物就向u连权值为1的边。
每次数组都要开的很大才可以过...........
#include<bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = 8e4+;
int head[maxn*], s, t, num, q[maxn], dis[maxn];
struct node
{
int to, nextt, c;
}e[maxn*];
void init() {
mem1(head);
num = ;
}
void add(int u, int v, int c) {
e[num].to = v; e[num].nextt = head[u]; e[num].c = c; head[u] = num++;
e[num].to = u; e[num].nextt = head[v]; e[num].c = ; head[v] = num++;
}
int bfs() {
int u, v, st = , ed = ;
mem(dis);
dis[s] = ;
q[ed++] = s;
while(st<ed) {
u = q[st++];
for(int i = head[u]; ~i; i = e[i].nextt) {
v = e[i].to;
if(e[i].c&&!dis[v]) {
dis[v] = dis[u]+;
if(v == t)
return ;
q[ed++] = v;
}
}
}
return ;
}
int dfs(int u, int limit) {
if(u == t)
return limit;
int cost = ;
for(int i = head[u]; ~i; i = e[i].nextt) {
int v = e[i].to;
if(e[i].c&&dis[u] == dis[v]-) {
int tmp = dfs(v, min(limit-cost, e[i].c));
if(tmp>) {
e[i].c -= tmp;
e[i^].c += tmp;
cost += tmp;
if(cost == limit)
break;
} else {
dis[v] = -;
}
}
}
return cost;
}
int dinic() {
int ans = ;
while(bfs()) {
ans += dfs(s, inf);
}
return ans;
}
char c[];
int main()
{
int n, f, d, x;
while(cin>>n>>f>>d) {
init();
s = , t = f+*n+d+;
for(int i = ; i<=f; i++) {
scanf("%d", &x);
add(s, i, x);
}
for(int i = ; i<=d; i++) {
scanf("%d", &x);
add(f+*n+i, t, x);
}
for(int k = ; k<; k++) {
for(int i = ; i<=n; i++) {
scanf("%s", c);
int len = strlen(c);
for(int j = ; j<len; j++) {
if(c[j]=='Y') {
if(k==) {
add(j+, f+i, );
} else {
add(f+n+i, j++f+*n, );
}
}
}
}
}
for(int i = ; i<=n; i++) {
add(i+f, i+n+f, );
}
int ans = dinic();
cout<<ans<<endl;
}
}
hdu 4292 Food 网络流的更多相关文章
- 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种 ...
- (网络流)Food -- hdu -- 4292
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4292 Food Time Limit: 2000/1000 MS (Java/Others) Me ...
- 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 2883 kebab 网络流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2883 Almost everyone likes kebabs nowadays (Here a ke ...
- hdu 1733 分层网络流 ****
题目大意:有一个类似于迷宫搜索的图,‘.’代表的是无人的路,'X'代表有人的点,'#'代表此点不可通过,'@'代表门口.每个位置每一秒钟只能站一个人,每个位置到上下左右点的时间为1,问你所有人能不能出 ...
- HDU 3452 Bonsai(网络流之最小割)
题目地址:HDU 3452 最小割水题. 源点为根节点.再另设一汇点,汇点与叶子连边. 对叶子结点的推断是看度数是否为1. 代码例如以下: #include <iostream> #inc ...
- hdu 3572 Escape 网络流
题目链接 给一个n*m的图, 里面有一些点, '.'代表空地, '#'代表墙, 不可以走, '@'代表大门, 可以有多个, 'X'代表人, 问所有人都走出大门需要的最短时间, 每一时刻一个格子只能有一 ...
随机推荐
- foreach真的比for性能高吗
void Main() { ; List<int> list=new List<int>(); ;i<count;i++) { list.Add(i); } List&l ...
- android入门——BroadCast(1)
使用广播要定义一个广播接收类,如 package com.example.wkp.broadcast; import android.content.BroadcastReceiver; import ...
- 第9课_3_db库安装
四 安装listener监听 使用oracle用户,在rac1和rac2上都可以起netca 1.打开网络配置界面,选择"Cluster configuration"集群配置方案, ...
- JAVA关键字transient
转载自http://www.cnblogs.com/liuling/archive/2013/05/05/transient.html 1.transient关键字只能修饰变量,而不能修饰方法和类.注 ...
- Android RadioGroup/RadioButton
RadioGroup RadioButton的集合,提供多选一的机制 属性: android:orientation="horizontal/vertical&quo ...
- [php]php时间戳当中关于时区的问题
PHP_VERSION = 5.5.11 话说php函数 time() 的起始时间戳是从:GMT 1970-01-01 00:00:00 开始算起的 写了点测试代码: $gmt1 = strtotim ...
- ueditor插件 -- 插入填空题
插入填空题,一个看似小小的需求,但是却是折腾了很9.主要产品那边的要求,空格上面要标有序号,并且再页面当中能够同步空格答案列表. 1.ueditor插件 插件入门,官方的例子还是很简单直接的,对于我们 ...
- C#学习日志 day10 -------------- problem statement
Revision History Date Issue Description Author 15/May/2015 1.0 Finish most of the designed function. ...
- Probability theory
1.Probability mass functions (pmf) and Probability density functions (pdf) pmf 和 pdf 类似,但不同之处在于所适用的分 ...
- 发送邮件java实现
下面代码可以实现普通qq邮箱发送邮件的功能,可以传附件,但是是固定的附件: 需要两个jar包:mail.jar,activation.jar mail.jar 下载地址: http://java.su ...