[最大权闭合子图][最小割] BZOJ 4873:寿司餐厅
来源:互联网 发布:淘宝店铺装修图片链接 编辑:程序博客网 时间:2024/04/27 22:19
Solution
对于
就是一个最大权闭合子图的模型,最小割即可。
刚开始忘掉写当前弧优化了。。。
#include <bits/stdc++.h>using namespace std;const int N = 211;const int INF = 1 << 28;inline char get(void) { static char buf[100000], *S = buf, *T = buf; if (S == T) { T = (S = buf) + fread(buf, 1, 100000, stdin); if (S == T) return EOF; } return *S++;}template<typename T>inline void read(T &x) { static char c; x = 0; int sgn = 0; for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1; for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0'; if (sgn) x = -x;}int n, m, S, T, cnt, Gcnt, clc, ans, mx;int a[N], w[N * 10], usd[N * 10];int d[N][N], id[N][N];struct edge { int to, next, flow; edge(int t = 0, int n = 0, int f = 0):to(t), next(n), flow(f) {}};edge G[N * N * N];int head[N * N], cur[N * N];int dis[N * N], vis[N * N];queue<int> Q;inline void AddEdge(int from, int to, int flow) { G[++Gcnt] = edge(to, head[from], flow); head[from] = Gcnt; G[++Gcnt] = edge(from, head[to], 0); head[to] = Gcnt;}inline bool bfs(int S, int T) { vis[S] = ++clc; Q.push(S); dis[S] = 0; while (!Q.empty()) { int x = Q.front(); Q.pop(); for (int i = head[x]; i; i = G[i].next) { edge &e = G[i]; if (e.flow && vis[e.to] != clc) { dis[e.to] = dis[x] + 1; vis[e.to] = clc; Q.push(e.to); } } } return vis[T] == clc;}inline int dfs(int u, int a) { if (u == T || !a) return a; int f, flow = 0; for (int &i = cur[u]; i; i = G[i].next) { edge &e = G[i]; if (e.flow && dis[e.to] == dis[u] + 1 && (f = dfs(e.to, min(e.flow, a))) > 0) { e.flow -= f; G[i ^ 1].flow += f; flow += f; a -= f; if (!a) break; } } return flow;}inline int MaxFlow(int S, int T) { int flow = 0; while (bfs(S, T)) { for (int i = 0; i <= cnt; i++) cur[i] = head[i]; flow += dfs(S, INF); } return flow;}int main(void) { freopen("1.in", "r", stdin); freopen("1.out", "w", stdout); read(n); read(m); Gcnt = 1; for (int i = 1; i <= n; i++) { read(a[i]); mx = max(mx, a[i]); } for (int i = 1; i <= n; i++) for (int j = i; j <= n; j++) { read(d[i][j]); id[i][j] = ++cnt; } for (int i = 1; i <= 1000; i++) w[i] = ++cnt; S = ++cnt; T = ++cnt; for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { if (i == j) { d[i][j] -= a[i]; AddEdge(id[i][i], w[a[i]], INF); } else { AddEdge(id[i][j], id[i + 1][j], INF); AddEdge(id[i][j], id[i][j - 1], INF); } if (d[i][j] < 0) AddEdge(id[i][j], T, -d[i][j]); else AddEdge(S, id[i][j], d[i][j]); if (d[i][j] > 0) ans += d[i][j]; } if (!usd[a[i]]) { usd[a[i]] = 1; AddEdge(w[a[i]], T, a[i] * a[i] * m); } } printf("%d\n", ans - MaxFlow(S, T)); return 0;}
阅读全文
0 0
- [最大权闭合子图][最小割] BZOJ 4873:寿司餐厅
- BZOJ 4873: [Shoi2017]寿司餐厅 (最大权闭合子图)
- [最大权闭合子图] BZOJ 4873 [Shoi2017]寿司餐厅
- bzoj 4873: [Shoi2017]寿司餐厅 最大权闭合子图
- [最大权闭合子图] BZOJ4873: [Shoi2017] 寿司餐厅
- bzoj 1497(最小割,最大权闭合子图)
- BZOJ 3996: [TJOI2015]线性代数 最大权闭合子图 最小割
- [BZOJ]1565: [NOI2009]植物大战僵尸 Tarjan+最小割(最大权闭合子图)
- 最大权闭合图 BZOJ 1497 最大获利 (最小割)
- POJ 2987 Firing 最小割(最大权闭合子图)
- pku2987 最小割,最大权闭合图
- 最小割---最大权闭合图简介
- [省选前题目整理][BZOJ 1565][NOI 2009]植物大战僵尸(最小割+最大权闭合子图建模)
- BZOJ 3438 最大权闭合子图
- BZOJ 1497 最大权闭合子图
- HDOJ 3879 - Base Station 最大权闭合子图(最小割解决)
- bzoj1497: [NOI2006]最大获利(最大权闭合子图,最小割)
- 最小割模型——最大权闭合子图 【NOI2006】bzoj1497 最大获利
- JS跳转页面后地址栏隐藏IP和端口号
- 20171213.3
- 前端学习资料
- Unity变换矩阵之如何构建变换矩阵
- wx订阅号 转载>>
- [最大权闭合子图][最小割] BZOJ 4873:寿司餐厅
- python3 集合操作
- 每个程序员都应该知道的基础数论
- 刚刚,阿里发布了一个技术重磅炸弹!
- 「BZOJ1095」「ZJOI2007」Hide 捉迷藏
- Python或将取代VBA,成为Excel官方脚本语言
- 程序员如何保护自己?
- 精心收集的 48 个 JavaScript 代码片段,仅需 30 秒就可理解!
- Code Patterns 简单的开发流程,致力于帮助全球技术精英