题面

BZOJ传送门

Luogu传送门

分析

考虑如何最小割建图,因为这仍然是二元关系,我们可以通过解方程来确定怎么建图,具体参考论文

<<浅析一类最小割问题 湖南师大附中 彭天翼>>

那么我们来看看怎么解方程



设存在一对二元关系&lt;x,y&gt;&lt;x,y&gt;<x,y>,那么假设分在SSS一边表示不雇佣,TTT一边表示雇佣.先把总收益全部加起来,那么只要考虑会每种情况会在此基础上减去多少.

  • 如果两个都雇佣 : a+b=A[x]+A[y]a+b=A[x]+A[y]a+b=A[x]+A[y]
  • 两个都不雇佣 : c+d=2∗E[x,y]c+d=2*E[x,y]c+d=2∗E[x,y]
  • 雇佣xxx : a+d+e=3∗E[x,y]+A[x]a+d+e=3*E[x,y]+A[x]a+d+e=3∗E[x,y]+A[x]
  • 雇佣yyy : b+c+e=3∗E[x,y]+A[y]b+c+e=3*E[x,y]+A[y]b+c+e=3∗E[x,y]+A[y]

    因为答案里已经算入x,yx,yx,y同时雇佣所带来的收益2∗E[x,y]2*E[x,y]2∗E[x,y],所以c+d=2∗E[x,y]c+d=2*E[x,y]c+d=2∗E[x,y]要减去

    又因为如果只雇佣一个,还会带来E[x,y]E[x,y]E[x,y]的损失,所以是3∗E[x,y]3*E[x,y]3∗E[x,y]

满足的一组解就是

a=A[x],b=A[y]a=A[x],b=A[y]a=A[x],b=A[y]

c=d=E[x,y]c=d=E[x,y]c=d=E[x,y]

e=2∗E[x,y]e=2*E[x,y]e=2∗E[x,y]

那么加上一些优化:

  • 把一个点到TTT的容量全部存起来最后只连一条边;
  • 最大流的一些小优化
  • 其实正常情况下eee是两条边(代码实现中要存444条),但是可以直接只连一条边(代码实现中只存222条),正向边的容量为eee,反向边的容量也设为eee而不是000.快很多.
  • freadfreadfread…

CODE

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
char cb[1<<15],*cs=cb,*ct=cb;
#define getc() (cs==ct && (ct = (cs = cb) + fread(cb , 1 , 1<<15 , stdin),cs==ct)?0:*cs++)
template<typename T>inline void read(T &num) {
char ch; while((ch=getc())<'0'||ch>'9');
for(num=0;ch>='0'&&ch<='9';num=num*10+ch-'0',ch=getc());
} const int inf = 1e9;
const int MAXN = 1005;
const int MAXM = 2000005;
const int dx[] = { 1, -1, 0, 0, 0 };
const int dy[] = { 0, 0, -1, 1, 0 };
int n, m, fir[MAXN], S, T, cnt;
struct edge { int to, nxt; LL c; }e[MAXM];
inline void add(int u, int v, LL cc, LL rc=0) {
e[cnt] = (edge){ v, fir[u], cc }; fir[u] = cnt++;
e[cnt] = (edge){ u, fir[v], rc }; fir[v] = cnt++;
}
int dis[MAXN], vis[MAXN], info[MAXN], cur, q[MAXN];
inline bool bfs() {
int head = 0, tail = 0;
vis[S] = ++cur; q[tail++] = S;
while(head < tail) {
int u = q[head++];
for(int i = fir[u]; ~i; i = e[i].nxt)
if(e[i].c && vis[e[i].to] != cur)
vis[e[i].to] = cur, dis[e[i].to] = dis[u] + 1, q[tail++] = e[i].to;
}
if(vis[T] == cur) memcpy(info, fir, (T+1)<<2);
return vis[T] == cur;
}
LL dfs(int u, LL Max) {
if(u == T || !Max) return Max;
LL flow=0, delta;
for(int &i = info[u]; ~i; i = e[i].nxt)
if(e[i].c && dis[e[i].to] == dis[u] + 1 && (delta=dfs(e[i].to, min(e[i].c, Max-flow)))) {
e[i].c -= delta, e[i^1].c += delta, flow += delta;
if(flow == Max) return flow;
}
return flow;
}
inline LL dinic() {
LL flow=0, x;
while(bfs()) {
while((x=dfs(S, inf))) flow+=x;
}
return flow;
}
LL sum, tmp[1005];
inline int enc(int i, int j) { return (i-1)*m + j; }
int main () {
memset(fir, -1, sizeof fir);
read(n); S = 0; T = n+1;
for(int i = 1, x; i <= n; ++i)
read(x), add(S, i, x);
for(int i = 1, x; i <= n; ++i)
for(int j = 1; j <= n; ++j) {
read(x);
if(x && i < j) {
sum += 2ll*x, tmp[i] += x, tmp[j] += x;
add(i, j, 2ll*x, 2ll*x);
}
}
for(int i = 1; i <= n; ++i)
if(tmp[i]) add(i, T, tmp[i]);
printf("%lld\n", sum-dinic());
}

BZOJ 2039 / Luogu P1791 [2009国家集训队]employ人员雇佣 (最小割)的更多相关文章

  1. 【BZOJ2039】[2009国家集训队]employ人员雇佣 最小割

    [BZOJ2039][2009国家集训队]employ人员雇佣 Description 作为一个富有经营头脑的富翁,小L决定从本国最优秀的经理中雇佣一些来经营自己的公司.这些经理相互之间合作有一个贡献 ...

  2. 【BZOJ2039】【2009国家集训队】人员雇佣 [最小割]

    人员雇佣 Time Limit: 20 Sec  Memory Limit: 259 MB[Submit][Status][Discuss] Description 作为一个富有经营头脑的富翁,小L决 ...

  3. BZOJ 2039: [2009国家集训队]employ人员雇佣

    2039: [2009国家集训队]employ人员雇佣 Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 1369  Solved: 667[Submit ...

  4. 【BZOJ 2039】 2039: [2009国家集训队]employ人员雇佣 (最小割)

    2039: [2009国家集训队]employ人员雇佣 Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 1511  Solved: 728 Descri ...

  5. BZOJ_2039_[2009国家集训队]employ人员雇佣_ 最小割

    BZOJ_2039_[2009国家集训队]employ人员雇佣_ 最小割 Description 作为一个富有经营头脑的富翁,小L决定从本国最优秀的经理中雇佣一些来经营自己的公司.这些经理相互之间合作 ...

  6. BZOJ 2039 [2009国家集训队]employ人员雇佣 网络流

    链接 BZOJ 2039 题解 这题建图好神,自己瞎搞了半天,最后不得不求教了企鹅学长的博客,,,,发现建图太神了!! s向每个人连sum(e[i][x]) 的边,每个人向T连a[i]的边.两两人之间 ...

  7. bzoj 2039 [2009国家集训队]employ人员雇佣——二元关系

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2039 用最小割看.对于一组关系 i , j ,如果都选,收益 2*Ei,j,可以看作0,作为 ...

  8. BZOJ 2039:[2009国家集训队]employ人员雇佣(最小割)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2039 题意:中文题意. 思路:一开始想着和之前做的最大权闭合图有点像,但是如果把边全部当成点的话,那 ...

  9. BZOJ2039 [2009国家集训队]employ人员雇佣

    AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=2039 鉴于一开始看题如果不仔细是看不懂题目的,还是说一下题目大意 [题目大意]:给定n个人 ...

随机推荐

  1. Prime Time UVA - 10200(精度处理,素数判定)

    Problem Description Euler is a well-known matematician, and, among many other things, he discovered ...

  2. python标准库之collections介绍

    collections----容器数据类型 collections模块包含了除list.dict.和tuple之外的容器数据类型,如counter.defaultdict.deque.namedtup ...

  3. Python面试题集合带答案

    目录 Python基础篇 1:为什么学习Python 2:通过什么途径学习Python 3:谈谈对Python和其他语言的区别 Python的优势: 4:简述解释型和编译型编程语言 5:Python的 ...

  4. 数据库与MySQL进阶(4)

    1,事务 事务指的是满足 ACID 特性的一组操作,可以通过 Commit 提交一个事务,也可以使用 Rollback 进行回滚. 1.1 ACID四大特性 原子性(Atomicity) 事务被视为不 ...

  5. Bminer

    Bminer https://www.bminer.me/zh/ Bminer: When Crypto-mining Made Fast¶ Bminer是一款为NVIDIA和AMD GPU深度优化的 ...

  6. QTabWidget标签实现双击关闭(转)

    重载了QTabWidget(由于tabBar()是protected),这样就可以获取到标签了. 1 class Tab : public QTabWidget 2 { 3 Q_OBJECT 4 pu ...

  7. vulnhub攻略

    https://www.vulnhub.com/entry/21ltr-scene-1,3/ 这个靶机国内https://www.cnblogs.com/hack404/p/11423228.html ...

  8. MySQL锁表解决方法

    https://blog.csdn.net/a5582ddff/article/details/79566678 MySQL锁表解决方法 一.我的处理过程 1.查进程,主要是查找被锁表的那个进程的ID ...

  9. java - day010 - 基本类型包装,自动装箱和拆箱,日期,集合

    基本类型的包装类 byte Byte short Short int Integer long Long float Float double Double char Character boolea ...

  10. 计算广告(4)----搜索广告召回(也叫match、触发)

    一.搜索广告形态 1.特征工程 特征主要有用户画像(user profile).用户行为(user behavior).广告(ad)和上下文(context)四部分组成,如下所示: 2.平台算法主要分 ...