
网络流
取竹
Hai capito?
展开
-
[hdu1569]方格取数(2) 最大点权独立集
题目大意:给你一个m*n的格子的棋盘,每个格子里面有一个非负数。从中取出若干个数,使得任意的两个数所在的格子没有公共边,就是说所取数所在的2个格子不能相邻,并且取出的数的和最大。我们首先将棋盘染成二色图(相邻点颜色不同),再将它想象成二分图。设立一个超级源点与超级会点,将超级源点与一种颜色相连,另一种颜色与超级会点相连,容量为格子权值。再将将相邻的异色格(从连接超级源点的格子到连接超级会点的格子)原创 2017-02-16 09:25:03 · 498 阅读 · 0 评论 -
[Loj]#6001. 「网络流 24 题」太空飞行计划
分析后看出是最大权闭合子图,那么答案就是正权值-最大流。#include #include #include #include #include #include #include using namespace std;const int N=2505;const int inf=1<<29;int m,n,sum,s,t;int cur[155];int h原创 2017-07-09 23:22:54 · 512 阅读 · 0 评论 -
[Loj] #6000. 「网络流 24 题」搭配飞行员
二分图最大匹配值,直接裸上匈牙利。#include #include using namespace std;const int N=105;int n,m;int a,b;int ans;bool vis[N];int fr[N];int ga[N][N];bool find(int x){ register int i; for (i=m+1;i<=n;i++)原创 2017-07-09 23:19:30 · 415 阅读 · 0 评论 -
(坑)网络流浅谈
对于网络流的建模不太熟悉,列举常用模型。最小割:二分图最大匹配:最小点权覆盖:最大权闭合子图:最小路径覆盖:最小边覆盖:最大点权独立集:原创 2017-07-14 22:20:46 · 280 阅读 · 0 评论 -
[bzoj]3876: [Ahoi2014]支线剧情
可以看出来是有上下界的费用流,我们对于一条边权为z的边u,v,从s向u连一条容量为1的边,从u到v连上容量为INF的边,让此边可以重复走。对于每个点p,从p到T连上一条流量为p,费用无的边,再从x到1连上一条费用无,流量无限的边,直接跑网络流就行了。跑的好慢啊。。。#include #include #include #include using namespace std原创 2017-07-12 23:35:20 · 3244 阅读 · 0 评论 -
[Loj]#6004. 「网络流 24 题」圆桌聚餐
建立源点s与所有单位连边,建立汇点T将所有餐桌与t相连,再将单位与餐桌各连上容量为1的边。跑一遍最大流即可。输出路径时,只要查看改变是否有流即可#include #include #include #include using namespace std;const int N=1005,INF=1<<29;int m,n,x,sum;struct node { int原创 2017-07-11 23:08:09 · 402 阅读 · 0 评论 -
[bzoj]1520: [POI2006]Szk-Schools
对于每座学校,都将它与可更换的值连上一条容量为1,权值为c*|a-m|的边。然后跑一遍费用流就行了。#include #include #include #include using namespace std;const int M=1000005,N=2005,Inf=1<<29;int n,m,a,b,c;struct edge{ int nxt,to,ro,c,fl原创 2017-07-11 22:37:28 · 338 阅读 · 0 评论 -
[Loj]#6003. 「网络流 24 题」魔术球
我是直接用贪心跑的,但其实可以用网络流来跑。对于网络流,通过分析可以得到,如果将i+j为完全平方数的i与j连上边。那么每一根柱子就是一条路径,答案就是有n条路径的最小路径覆盖。可以自己画图YY。#include #include #include using namespace std;const int N=65;int n;vector v[N];inline b原创 2017-07-10 22:55:02 · 494 阅读 · 0 评论 -
[Loj]#6002. 「网络流 24 题」最小路径覆盖
题意如题名,最小路径覆盖。答案为点数减去最小割。用dinic直接跑。#include #include #include using namespace std;const int N=205;int n,m;int map[N][N];int fr[N];int vis[N];int sum;int in[N];int le;int fa[N]原创 2017-07-09 23:25:18 · 395 阅读 · 0 评论 -
[2017百度之星程序设计大赛 - 复赛]F - hdu6149
因为是三元组<x,y,z><x,y,z> 暴力枚举处于x位置的高谷,然后建网络流的图,每次跑dinic取最大流。 枚举位置时直接dfs,上界是高谷总数的一半。 可以证明答案一定在dfs出的结果内。#include <cstdio>#include <queue>#include <cstring>using namespace std;int T,n,m,k,kd;int hi[10原创 2017-09-11 20:10:43 · 310 阅读 · 0 评论