POJ3281_Dining
有一些饮料和食物,每种一个,每个客人喜欢一些饮料和一些食物,每个客人可以选择一种饮料和一种食物,问最多能够同时满足多少个客人同时拥有饮料和食物。
这样的,源点连接饮料,汇点连接食物,中间人分别连接饮料和食物。
然后这样直接跑最大流。。。。。是错的。
因为没有保证每个人只拿一种饮料和一种食物。
还需要对每个人拆点,保证每人所拥有的饮料和食物都不超过1,最终最大流就是最多能够满足条件的人数了。
召唤代码君:
#include <iostream>
#include <cstdio>
#include <cstring>
#define maxn 5550
#define maxm 555550
using namespace std; int to[maxm],next[maxm],c[maxm],first[maxn],edge;
int d[maxn],tag[maxn],TAG=;
int Q[maxn],bot,top;
bool can[maxn];
int N,F,D,s,t,ans; void _init()
{
s=,t=N+N+F+D+,edge=-;
for (int i=s; i<=t; i++) first[i]=-;
} void addedge(int U,int V)
{
edge++;
to[edge]=V,c[edge]=,next[edge]=first[U],first[U]=edge;
edge++;
to[edge]=U,c[edge]=,next[edge]=first[V],first[V]=edge;
} void _input()
{
for (int i=; i<=N; i++) addedge(F+i,F+N+D+i);
for (int i=; i<=F; i++) addedge(s,i);
for (int i=; i<=D; i++) addedge(F+N+i,t);
int food,drink,tmp;
for (int i=; i<=N; i++)
{
scanf("%d%d",&food,&drink);
while (food--)
{
scanf("%d",&tmp);
addedge(tmp,F+i);
}
while (drink--)
{
scanf("%d",&tmp);
addedge(F+N+D+i,F+N+tmp);
}
}
} bool bfs()
{
Q[bot=top=]=t,d[t]=,tag[t]=++TAG,can[t]=false;
while (bot<=top)
{
int cur=Q[bot++];
for (int i=first[cur]; i!=-; i=next[i])
if (c[i^]> && tag[to[i]]!=TAG)
{
tag[to[i]]=TAG,d[to[i]]=d[cur]+;
can[to[i]]=false,Q[++top]=to[i];
if (to[i]==s) return true;
}
}
return false;
} int dfs(int cur,int num)
{
if (cur==t) return num;
int tmp=num,k;
for (int i=first[cur]; i!=-; i=next[i])
if (c[i]> && tag[to[i]]==TAG && d[to[i]]==d[cur]- && !can[to[i]])
{
k=dfs(to[i],min(num,c[i]));
if (k) num-=k,c[i]-=k,c[i^]+=k;
if (num==) break;
}
if (num) can[cur]=true;
return tmp-num;
} int main()
{
while (scanf("%d%d%d",&N,&F,&D)!=EOF)
{
_init();
_input();
for (ans=; bfs(); ) ans+=dfs(s,);
printf("%d\n",ans);
}
return ;
}
POJ3281_Dining的更多相关文章
随机推荐
- IDEA中java文件的左下角有个像乐符一样的J符号
- UWP 五星评价(不跳转到龟速商店)
之前写过一篇文章 UWP 五星好评 代码如下 var pfn = Package.Current.Id.FamilyName; await Launcher.LaunchUriAsync(new ...
- Convert Application Model Differences
The eXpressApp Framework is based on the modules concept. As a rule, every module implements a certa ...
- PowerDesigner中翻转生成PDM图时把Name属性变成注释(转)
在pd里面运行下面这段代码'******************************************************************************'* File: ...
- Python学习之路:NumPy初识
import numpy as np; //一维NumPy数组 myArray = np.array([1,2,3,4]); print(myArray); [1 2 3 4] //打印一维数组的形状 ...
- [算法总结] 20 道题搞定 BAT 面试——二叉树
本文首发于我的个人博客:尾尾部落 0. 几个概念 完全二叉树:若二叉树的高度是h,除第h层之外,其他(1~h-1)层的节点数都达到了最大个数,并且第h层的节点都连续的集中在最左边.想到点什么没?实际上 ...
- Windows 8.1 "计算机" 中文件夹清理
计算机 win8.1 也叫这台电脑 清理文件夹 保留磁盘分区图标 注册表清理 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\ ...
- 第39次Scrum会议(12/5)【欢迎来怼】
一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,阚博文 小组照片 二.开会信息 时间:2017/12/5 11:35~11:57,总计22min.地点:东北师 ...
- jQuery全屏滚动插件fullPage使用
1. 引入jquery.js和jquery.fullPage.min.js <script src="jquery.min.js"></script> &l ...
- 用java进行简单的万年历编写
import java.util.Scanner; public class PrintCalendarDemo1 { public static void main(String[] args) { ...