P1402 酒店之王

提交 5.39k
通过 2.16k
时间限制 1.00s
内存限制 125.00MB
题目提供者yeszy
历史分数100

提交记录

查看算法标签
进入讨论版

相关讨论

 
查看讨论

推荐题目

 
查看推荐
 

展开

题目描述

XX酒店的老板想成为酒店之王,本着这种希望,第一步要将酒店变得人性化。由于很多来住店的旅客有自己喜好的房间色调、阳光等,也有自己所爱的菜,但是该酒店只有p间房间,一天只有固定的q道不同的菜。

有一天来了n个客人,每个客人说出了自己喜欢哪些房间,喜欢哪道菜。但是很不幸,可能做不到让所有顾客满意(满意的条件是住进喜欢的房间,吃到喜欢的菜)。

这里要怎么分配,能使最多顾客满意呢?

输入格式

第一行给出三个正整数表示n,p,q(<=100)。

之后n行,每行p个数包含0或1,第i个数表示喜不喜欢第i个房间(1表示喜欢,0表示不喜欢)。

之后n行,每行q个数,表示喜不喜欢第i道菜。

输出格式

最大的顾客满意数。

输入输出样例

输入 #1
2 2 2

1 0

1 0

1 1

1 1
输出 #1
1

思路:
  本来想用来练习二分匹配,但是发现匈牙利算法好像无法解决两个关联的二分图问题,画的图却很像拆点的最大流。
  只要把菜或房单独连向超级源、汇,再把人拆开做一个流入流出,随后套dinic的模板就行了。
  不知道为什么ISAP只能过7个点,如果有ISAP过的同学可以教教我嘛。
 #include <bits/stdc++.h>

 using namespace std;
const int maxn = ; int s,t,flow;
int head[maxn];
int pre[maxn];
int n,p,q;
int cnt = ;
int a[maxn]; template<class T>inline void read(T &res)
{
char c;T flag=;
while((c=getchar())<''||c>'')if(c=='-')flag=-;res=c-'';
while((c=getchar())>=''&&c<='')res=res*+c-'';res*=flag;
} struct Edge {
int to, nxt, cap;
}edge[maxn]; void BuildGraph(int u, int v, int cap) {
edge[++cnt].to = v;
edge[cnt].nxt = head[u];
edge[cnt].cap = cap;
head[u] = cnt; edge[++cnt].to = u;
edge[cnt].nxt = head[v];
edge[cnt].cap = ;
head[v] = cnt;
} bool bfs() {
queue <int> q;
memset(a, , sizeof(a));
a[s] = 0x3f3f3f3f;
q.push(s);
while(!q.empty()) {
int u = q.front();
q.pop();
for(int i = head[u]; i; i = edge[i].nxt) {
int to = edge[i].to;
if(!edge[i].cap) {
continue;
}
if(a[to]) {
continue;
}
a[to] = min(a[u], edge[i].cap);
pre[to] = i;
q.push(to);
}
}
if(!a[t]) {
return ;
}
flow += a[t];
return ;
} void Dinic() {
int m = t;
for(; pre[m]; m = edge[pre[m]^].to) {
edge[pre[m]].cap -= a[t];
edge[pre[m]^].cap += a[t];
}
} int main()
{
read(n), read(p), read(q);
s = *n+q+p+;
t = s+;
for(int i = ; i <= n; ++i) {
for(int x, j = ; j <= p; ++j) {
read(x);
if(x) {
BuildGraph(j, p+i, );
}
}
}
for(int i = ; i <= n; ++i) {
for(int x, j = ; j <= q; ++j) {
read(x);
if(x) {
BuildGraph(p+n+q+i, p+n+j, );
}
}
}
for(int i = ; i <= n; ++i) {
BuildGraph(p+i, p+n+q+i,);
}
for(int i = ; i <= p; ++i) {
BuildGraph(s, i, );
}
for(int i = p+n+; i <= p+q+n; ++i) {
BuildGraph(i, t, );
}
while(bfs()) {
Dinic();
}
printf("%d\n",flow);
return ;
}

最新文章

  1. DOM扩展之 HTML5
  2. Android深度探索HAL和驱动开发(卷1) 第一章 Android系统移植和驱动开发
  3. AngularJS中的过滤器
  4. nodejs-express 报错View is not a constructor
  5. BNUOJ 1006 Primary Arithmetic
  6. 无线路由器WDS设置方法图解_无线桥接设置
  7. C# Lazy&lt;T&gt;(转)
  8. NSURLConnect 的简单实用(iOS8淘汰)
  9. eclipse配置自动提示EXTJS和jQurey
  10. IO的五种模型
  11. 华为ensp模拟某公司网络架构及配置详解
  12. 三种计算c#程序运行时间的方法
  13. iBATIS使用$和#的一些理解
  14. Centos7下安装MySql
  15. android Fragment中使用Toolbar
  16. Java学习点滴——初识Java
  17. Spring-WebSocket 教程
  18. 开发神器之phpstorm破解与日常使用
  19. 基于Verilog的串口发送程序
  20. wxPython:事件处理一

热门文章

  1. Linux文件结构-底层文件访问&amp;文件目录和维护
  2. 通过LD_PRELOAD绕过disable_functions
  3. Numerical Testing Reportes of A New Conjugate Gradient Projection Method for Convex Constrained Nonlinear Equations
  4. 声明式服务调用:Spring Cloud Feign
  5. Bash脚本编程学习笔记04:测试命令test、状态返回值、位置参数和特殊变量
  6. 战“疫”背后的AI身影丨曼孚科技
  7. mysql查询中字符串转换成数字
  8. GHO文件安装到Vmware的两种姿势
  9. LeetCode30 Hard 查找所有子串
  10. Java泛型(T)与通配符?