http://acm.hdu.edu.cn/showproblem.php?pid=4292

题意:和奶牛一题差不多,只不过每种食物可以有多种。

思路:因为食物多种,所以源点和汇点的容量要改下。还有Dinic又TLE了,用ISAP过。

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define INF 0x3f3f3f3f
#define N 910
typedef long long LL;
typedef long long LL;
struct Edge {
int v, cap, nxt;
Edge () {}
Edge (int v, int cap, int nxt) : v(v), cap(cap), nxt(nxt) {}
}edge[N*N];
int tot, cur[N], dis[N], pre[N], head[N], gap[N], S, T; void Add(int u, int v, int cap) {
edge[tot] = Edge(v, cap, head[u]); head[u] = tot++;
edge[tot] = Edge(u, , head[v]); head[v] = tot++;
} void BFS() {
queue<int> que;
while(!que.empty()) que.pop();
memset(dis, -, sizeof(dis));
memset(gap, , sizeof(gap));
dis[T] = ; gap[]++; que.push(T);
while(!que.empty()) {
int u = que.front(); que.pop();
for(int i = head[u]; ~i; i = edge[i].nxt) {
int v = edge[i].v;
if(dis[v] == -) continue;
dis[v] = dis[u] + ;
gap[dis[v]]++;
que.push(v);
}
}
} int ISAP(int n) {
memcpy(cur, head, sizeof(cur));
BFS();
int u = pre[S] = S, ans = , i;
while(dis[S] < n) {
if(u == T) {
int flow = INF, index;
for(int i = S; i != T; i = edge[cur[i]].v) {
Edge& e = edge[cur[i]];
if(e.cap < flow) {
flow = e.cap; index = i;
}
}
for(int i = S; i != T; i = edge[cur[i]].v) {
edge[cur[i]].cap -= flow;
edge[cur[i]^].cap += flow;
}
ans += flow; u = index;
}
for(i = cur[u]; ~i; i = edge[i].nxt)
if(dis[edge[i].v] == dis[u] - && edge[i].cap > )
break;
if(~i) {
cur[u] = i;
pre[edge[i].v] = u;
u = edge[i].v;
} else {
int md = n;
if(--gap[dis[u]] == ) break;
for(int i = head[u]; ~i; i = edge[i].nxt) {
if(md > dis[edge[i].v] && edge[i].cap > ) {
md = dis[edge[i].v]; cur[u] = i;
}
}
++gap[dis[u] = md + ];
u = pre[u];
}
}
return ans;
} int main() {
int n, f, d;
while(~scanf("%d%d%d", &n, &f, &d)) {
S = , T = * n + f + d + ;
memset(head, -, sizeof(head));
tot = ; int a; char s[];
for(int i = ; i <= f; i++) {
scanf("%d", &a);
Add(S, i + * n, a);
}
for(int i = ; i <= d; i++) {
scanf("%d", &a);
Add(i + * n + f, T, a);
}
for(int i = ; i <= n; i++) {
Add(i, i + n, );
scanf("%s", s + );
for(int j = ; j <= f; j++) {
if(s[j] == 'Y') {
Add( * n + j, i, );
}
}
}
for(int i = ; i <= n; i++) {
scanf("%s", s + );
for(int j = ; j <= d; j++) {
if(s[j] == 'Y') {
Add(i + n, * n + j + f, );
}
}
}
printf("%d\n", ISAP(T + ));
}
return ;
}

HDU 4292:Food(最大流)的更多相关文章

  1. HDU 4292 Food 最大流

    Food Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. HDU 4292 Food (网络流,最大流)

    HDU 4292 Food (网络流,最大流) Description You, a part-time dining service worker in your college's dining ...

  3. hdu 4292 最大流 水题

    很裸的一道最大流 格式懒得排了,注意把人拆成两份,一份连接食物,一份连接饮料 4 3 3 //4个人,3种食物,3种饮料 1 1 1 //食物每种分别为1 1 1 1 //饮料每种数目分别为1 YYN ...

  4. H - Food - hdu 4292(简单最大流)

    题目大意:有N个人,然后有F种食品和D种饮料,每个人都有喜欢的饮料和食品,求出来这些食品最多能满足多少人的需求. 输入描述: 分析:以前是做过类似的题目的,不过输入的信息量比较大,还是使用邻接表的好些 ...

  5. HDU 4292 Food (拆点最大流)

    题意:N个人,F种食物,D种饮料,给定每种食物和饮料的量.每个人有自己喜欢的食物和饮料,如果得到自己喜欢的食物和饮料才能得到满足.求最大满足的人数. 分析:如果只是简单地N个人选择F种食物的话可以用二 ...

  6. HDU 4292 Food (建图思维 + 最大流)

    (点击此处查看原题) 题目分析 题意:某个餐馆出售f种食物,d种饮料,其中,第i种食物有fi份,第i种饮料有di份:此时有n个人来餐馆吃饭,这n个人必须有一份食物和一份饮料才会留下来吃饭,否则,他将离 ...

  7. HDU 3549 网络最大流再试

    http://acm.hdu.edu.cn/showproblem.php?pid=3549 同样的网络最大流 T了好几次原因是用了cout,改成printf就A了 还有HDU oj的编译器也不支持以 ...

  8. Food HDU - 4292 网络流 拆点建图

    http://acm.hdu.edu.cn/showproblem.php?pid=4292 给一些人想要的食物和饮料,和你拥有的数量,问最多多少人可以同时获得一份食物和一份饮料 写的时候一共用了2种 ...

  9. (网络流)Food -- hdu -- 4292

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4292 Food Time Limit: 2000/1000 MS (Java/Others)    Me ...

随机推荐

  1. localstorage 的属性改变问题

    localstorage 得到的是对象,我们打算改对象的某个属性的值,方法是 通过临时变量对象得到,改变临时变量,然后把临时变量给localstorage的方法 var localS  = windo ...

  2. 微信 {"errcode":40029,"errmsg":"invalid code, hints: [ req_id: Cf.y.a0389s108 ]"}

    {"errcode":,"errmsg":"invalid code, hints: [ req_id: Cf.y.a0389s108 ]" ...

  3. Thinking in Java——笔记(14)

    Type Information The need for RTTI Because it is a dynamically bound method, the proper behavior wil ...

  4. LoadRunner - 001

    lr_eval_string():函数的主要作用:返回脚本中的一个参数当前的值,返回值类型:char一般多用在调试脚本时输出参数的值.具体用法如下:lr_output_message("Th ...

  5. ife任务刷题总结(一)-css reset与清除浮动

    本文同时发布于本人的个人网站www.yaoxiaowen.com 百度创办的前端技术学院,是一个面向大学生的前端技术学习平台.虽然只有大学生才有资格报名,提交代码进行比赛排名.但是这并不妨碍我们这些初 ...

  6. virturalbox 本地win8 虚拟机为Linux-- 网络设置

    网络地址转换 NAT(适合Linux临时上网,无法连接本地网络)  ,Linux需要设置为自动连接 既DHCP,并service network restart 桥接 适合本地和虚拟机对接,虚拟机网络 ...

  7. MVC+knocKout.js 实现下拉框级联

    数据库:部门表和员工表 在控制器里面的操作: public ActionResult Index3() { ViewBag.departments = new SelectList(getDepart ...

  8. Dubbo学习

    可以看这个文档 http://dubbo.io/User+Guide-zh.htm 1.简介 Dubbo是一个框架,它能够暴露某个系统的服务接口,使得其他系统能够使用该系统的接口 Dubbo的框架如下 ...

  9. ps用画笔工具设计水墨圆环

    1.打开ps,新建一个1500*1500px的空白文档,分辨率为72,背景选择白色,如图: 2.选择画笔工具,按F5调出画笔预设面板,设置参数. 画笔笔尖形状:选择27号画笔,找不到可以复位一下画笔: ...

  10. 采用阿里的API进行动态域名解析

    #!/usr/bin/env python # -*- coding:utf-8 -*- import os from aliyunsdkcore import client from aliyuns ...