传送门

Luogu

解题思路

网络流板子题。

建图细节见代码,也可以参考这道差不多的题

细节注意事项

  • 咕咕咕。

参考代码

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#define rg register
using namespace std;
template < class T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) s = s * 10 + c - 48, c = getchar();
s = f ? -s : s;
} const int _ = 502;
const int __ = 30002;
const int INF = 2147483647; int tot = 1, head[_], nxt[__ << 1], ver[__ << 1], cap[__ << 1];
inline void Add_edge(int u, int v, int d)
{ nxt[++tot] = head[u], head[u] = tot, ver[tot] = v, cap[tot] = d; }
inline void link(int u, int v, int d) { Add_edge(u, v, d), Add_edge(v, u, 0); } int n, p, q, s, t, dep[_], cur[_]; inline int bfs() {
static queue < int > Q;
memset(dep, 0, sizeof (int) * (t - s + 1));
dep[s] = 1, Q.push(s);
while (!Q.empty()) {
int u = Q.front(); Q.pop();
for (rg int i = head[u]; i; i = nxt[i]) {
int v = ver[i];
if (dep[v] == 0 && cap[i] > 0)
dep[v] = dep[u] + 1, Q.push(v);
}
}
return dep[t] > 0;
} inline int dfs(int u, int flow) {
if (u == t) return flow;
for (rg int& i = cur[u]; i; i = nxt[i]) {
int v = ver[i];
if (dep[v] == dep[u] + 1 && cap[i] > 0) {
int res = dfs(v, min(flow, cap[i]));
if (res) { cap[i] -= res, cap[i ^ 1] += res; return res; }
}
}
} inline int Dinic() {
int res = 0;
while (bfs()) {
for (rg int i = s; i <= t; ++i) cur[i] = head[i];
while (int d = dfs(s, INF)) res += d;
}
return res;
} int main() {
#ifndef ONLINE_JUDGE
freopen("cpp.in", "r", stdin);
freopen("cpp.out", "w", stdout);
#endif
read(n), read(p), read(q);
s = 0, t = p + 2 * n + q + 1;
int f;
for (rg int i = 1; i <= n; ++i)
for (rg int j = 1; j <= p; ++j) {
read(f); if (f) link(j, i + p, 1);
}
for (rg int i = 1; i <= n; ++i)
for (rg int j = 1; j <= q; ++j) {
read(f); if (f) link(i + p + n, j + p + 2 * n, 1);
}
for (rg int i = 1; i <= n; ++i) link(i + p, i + p + n, 1);
for (rg int i = 1; i <= p; ++i) link(s, i, 1);
for (rg int i = 1; i <= q; ++i) link(i + p + 2 * n, t, 1);
printf("%d\n", Dinic());
return 0;
}

完结撒花 \(qwq\)

「Luogu1402」酒店之王的更多相关文章

  1. 「LuoguP1402」 酒店之王(最大流

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

  2. 「洛谷P1402」酒店之王 解题报告

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

  3. [luogu1402]酒店之王_网络流

    酒店之王 luogu-1402 题目大意:有n个人,p道菜,q个房间,每个人喜欢吃一些菜.喜欢住一些房间,如果一个人即住到了他喜欢的房间有吃到了他喜欢的菜,就对答案贡献++,求最大贡献. 注释:1&l ...

  4. luogu1402 酒店之王

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

  5. 2019 年在 Raspberry Pi 「树莓派」上运行的 10 个操作系统推荐

    原文:2019 年在 Raspberry Pi 「树莓派」上运行的 10 个操作系统推荐 image Raspberry Pi** 是一款基于 ARM 的单板计算机,默认运行一款称为 Raspbian ...

  6. 「MoreThanJava」当大学选择了计算机之后应该知道的

    「MoreThanJava」 宣扬的是 「学习,不止 CODE」,本系列 Java 基础教程是自己在结合各方面的知识之后,对 Java 基础的一个总回顾,旨在 「帮助新朋友快速高质量的学习」. 当然 ...

  7. 「译」JUnit 5 系列:条件测试

    原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...

  8. 「译」JUnit 5 系列:扩展模型(Extension Model)

    原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...

  9. JavaScript OOP 之「创建对象」

    工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...

随机推荐

  1. Spring Boot FreeMarker 使用教程

    FreeMarker 跟 Thymeleaf 一样,是一种模板引擎,他可以无缝兼容 FreeMarker 在 Spring Boot 开发者中仍然有着很高的地位. 本章重点内容 编写一个最简单的 Fr ...

  2. Spring Boot 缓存应用 Memcached 入门教程

    本章学习 Mmecached 在 Spring Boot 中的使用教程.Memcached 与 Redis 各有好处.本文主要学习 Spring Boot 中如何应用集成 Mmecached spri ...

  3. Meaven搭建springboot项目

    1.创建一个简单的maven project项目 2.项目目录结构 **注意启动类的位置: 3.pom.xml 配置jar包 <parent> <groupId>org.spr ...

  4. 两个list 集合比较属性不同的值

    for(Stall stall : stallList){ boolean flag = false; for(DeliveryStallCommission deliveryStallCommiss ...

  5. 「ZJOI2011」最小割

    「ZJOI2011」最小割 传送门 建出最小割树,然后暴力计算任意两点之间最小割即可. 多组数据记得初始化. 参考代码: #include <algorithm> #include < ...

  6. Django 学习之Rest Framework 视图相关

    drf除了在数据序列化部分简写代码以外,还在视图中提供了简写操作.所以在django原有的django.views.View类基础上,drf封装了多个子类出来提供给我们使用. Django REST ...

  7. 记处理spring-devtools 和 通用mapper 使用问题

    问题: tk.mybatis.mapper.MapperException: 无法获取实体类com.*.* 对应的表名 环境: springboot 2.0.6, 通用mapper 2.0.4,还有 ...

  8. Lucene学习笔记一

    Lucene课件 1.全文检索 1.1常见的全文检索 在window系统中,可以指定磁盘中的某一个位置来搜索你想要得到的东西.这个功能是windows比较常用的功能.在这个界面中能搜索的内容有*.*, ...

  9. Python数据类型-1 数据类型介绍

    数据类型 在python这门语言中,数据类型分为两种. 内置的和自定义的. 内置的包括数字.字符串.布尔.列表.元组.字典.Bytes.集合这些常用的以及一些不太常用的数据类型.而自定义的,一般以类的 ...

  10. Integer a = 200,b=200比较详解

    题记:前几天面试Java基础给来了个面试题Integer a=200,b=200;System.out.println(a==b);当时回答是false,后来面试官又来了一个Integer a=100 ...