HDU 4292:Food(最大流)
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(最大流)的更多相关文章
- HDU 4292 Food 最大流
Food Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 4292 Food (网络流,最大流)
HDU 4292 Food (网络流,最大流) Description You, a part-time dining service worker in your college's dining ...
- hdu 4292 最大流 水题
很裸的一道最大流 格式懒得排了,注意把人拆成两份,一份连接食物,一份连接饮料 4 3 3 //4个人,3种食物,3种饮料 1 1 1 //食物每种分别为1 1 1 1 //饮料每种数目分别为1 YYN ...
- H - Food - hdu 4292(简单最大流)
题目大意:有N个人,然后有F种食品和D种饮料,每个人都有喜欢的饮料和食品,求出来这些食品最多能满足多少人的需求. 输入描述: 分析:以前是做过类似的题目的,不过输入的信息量比较大,还是使用邻接表的好些 ...
- HDU 4292 Food (拆点最大流)
题意:N个人,F种食物,D种饮料,给定每种食物和饮料的量.每个人有自己喜欢的食物和饮料,如果得到自己喜欢的食物和饮料才能得到满足.求最大满足的人数. 分析:如果只是简单地N个人选择F种食物的话可以用二 ...
- HDU 4292 Food (建图思维 + 最大流)
(点击此处查看原题) 题目分析 题意:某个餐馆出售f种食物,d种饮料,其中,第i种食物有fi份,第i种饮料有di份:此时有n个人来餐馆吃饭,这n个人必须有一份食物和一份饮料才会留下来吃饭,否则,他将离 ...
- HDU 3549 网络最大流再试
http://acm.hdu.edu.cn/showproblem.php?pid=3549 同样的网络最大流 T了好几次原因是用了cout,改成printf就A了 还有HDU oj的编译器也不支持以 ...
- 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 ...
随机推荐
- java beans
There are N little kids sitting in a circle, each of them are carrying some java beans in their hand ...
- Ionic + AngularJS
Ionic Framework Ionic framework is the youngest in our top 5 stack, as the alpha was released in lat ...
- 【转】Mecanim Animator使用详解
http://blog.csdn.net/myarrow/article/details/45242403 1. 简介 Mecanim把游戏中的角色设计提高到了一个新的层次,使用Mecanim可以通过 ...
- 个人理解java的继承
java的类是属于单继承的.在继承这一块上我本来有一个很大的误区,就是觉得父类中private定义的成员无法被继承.直到网上的大神给我指出private是可以被继承的,会在内存中,只是在子类的对象中不 ...
- ASP.NET Web Api
1.参考资料 Routing in Asp.NET Web Api: http://www.asp.net/web-api/overview/web-api-routing-and-actions/r ...
- Cookie和Session的区别详解
本文引用自:http://www.cnblogs.com/shiyangxt/archive/2008/10/07/1305506.html 二者的定义: 当你在浏览网站的时候,WEB 服务器会先送一 ...
- sprint2总结
在sprint第二阶段的学习过程中,前期和后期在学校网络的支持下我们成功的延迟了把代码上传github的时间,在我们自己感觉上看,完成项目的质量比较理想,在经过sprint第一阶段的学习后,部分上的问 ...
- angularJS实现二级联动查询以及自定义过滤器的使用
<!DOCTYPE html><html lang="en"><head> <meta http-equiv="Conte ...
- mysql主键uuid、uuid_short和int自增对比
数据库主键性能对比: 名称 存储长度 生成方式 1. uuid 32+4 uuid()函数 2. uuid20 20 UUID_SHORT()函数 3. bigint自增 20 auto_increm ...
- AppScan漏洞“已解密的登陆请求”修复解决方案
最近在修复系统漏洞时,使用新版AppScan扫描IIS站点(WebForm)出现一个严重漏洞“已解密的登陆请求”. 扫描工具修复的建议为在登陆界面不使用含“password”类型的控件或加密录入参数. ...