_bzoj1061 [Noi2008]志愿者招募【最小费用最大流】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1061
尽管不是mcmf的裸题,但还是保存一下模版叭~
很好的一道建模的题,把变量间的加加减减等效成网络中的流入流量与流出流量,再带上个权,求个最小费用就好,详细题解间此:https://www.byvoid.com/blog/noi-2008-employee/
#include <cstdio>
#include <cstring>
#include <algorithm> const int maxn = 1010, maxm = 10005, maxe = 100000;
const long long inf = 0x3c3c3c3c3c3c3c3cLL; int n, m, a[maxn], s[maxm], t[maxm], cost[maxm], S, T;
int head[maxn], to[maxe], next[maxe], from[maxe], lb;
long long d[maxn], c[maxn], w[maxe], flow[maxe], cap[maxe];
int p[maxn], que[maxn], head_, tail, h;
bool inq[maxn]; inline bool spfa(long long & co) {
memset(d, 0x3c, sizeof d);
head_ = tail = 0;
memset(inq, 0, sizeof inq);
que[tail++] = S;
inq[S] = 1;
c[S] = inf;
d[S] = 0;
while (head_ != tail) {
h = que[head_++];
inq[h] = 0;
if (head_ == T + 3) {
head_ = 0;
}
for (int j = head[h]; j != -1; j = next[j]) {
if (cap[j] > flow[j] && d[to[j]] > d[h] + w[j]) {
d[to[j]] = d[h] + w[j];
c[to[j]] = std::min(c[h], cap[j] - flow[j]);
p[to[j]] = j;
if (!inq[to[j]]) {
que[tail++] = to[j];
inq[to[j]] = 1;
if (tail == T + 3) {
tail = 0;
}
}
}
}
}
if (d[T] == inf) {
return false;
}
co += d[T] * c[T];
for (int i = T; i != S; i = from[p[i]]) {
flow[p[i]] += c[T];
flow[p[i] ^ 1] -= c[T];
}
return true;
}
inline long long mcmf(void) {
long long co = 0;
while (spfa(co));
return co;
} inline void ist(int aa, int ss, long long ww, long long ca) {
to[lb] = ss;
from[lb] = aa;
next[lb] = head[aa];
head[aa] = lb;
w[lb] = ww;
cap[lb] = ca;
++lb; to[lb] = aa;
from[lb] = ss;
next[lb] = head[ss];
head[ss] = lb;
w[lb] = -ww;
cap[lb] = 0;
++lb;
} int main(void) {
//freopen("in.txt", "r", stdin);
memset(head, -1, sizeof head);
memset(next, -1, sizeof next);
scanf("%d%d", &n, &m);
T = n + 2;
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
}
for (int i = 1; i <= m; ++i) {
scanf("%d%d%d", s + i, t + i, cost + i);
} for (int i = 1; i <= n + 1; ++i) {
if (a[i - 1] - a[i] >= 0) {
ist(S, i, 0, (long long)(a[i - 1] - a[i]));
}
else {
ist(i, T, 0, (long long)(a[i] - a[i - 1]));
}
}
for (int i = 1; i <= m; ++i) {
ist(t[i] + 1, s[i], (long long)cost[i], inf);
}
for (int i = 1; i <= n; ++i) {
ist(i, i + 1, 0, inf);
}
printf("%lld\n", mcmf());
return 0;
}
_bzoj1061 [Noi2008]志愿者招募【最小费用最大流】的更多相关文章
- bzoj 1061 志愿者招募(最小费用最大流)
[Noi2008]志愿者招募 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 3792 Solved: 2314[Submit][Status][Di ...
- 【BZOJ】1061: [Noi2008]志愿者招募(费用流+数学)
http://www.lydsy.com/JudgeOnline/problem.php?id=1061 好神的一题! 学会了一种建模方式: 当方程组内的任意变量都在其中两个方程出现且一正一负,可以建 ...
- BZOJ 1061 [Noi2008]志愿者招募(费用流)
题目描述 申奥成功后,布布经过不懈努力,终于成为奥组委下属公司人力资源部门的主管.布布刚上任就遇到了一个难题:为即将启动的奥运新项目招募一批短期志愿者.经过估算,这个项目需要N 天才能完成,其中第i ...
- NOI2008 志愿者招募 (费用流)
题面 申奥成功后,布布经过不懈努力,终于成为奥组委下属公司人力资源部门的主管.布布刚上任就遇到了一个难题:为即将启动的奥运新项目招募一批短期志愿者.经过估算,这个项目需要N 天才能完成,其中第i 天至 ...
- [BZOJ1061][Noi2008]志愿者招募 线性规划+费用流
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1061 根据题意列方程,然后用网络流解线性规划. 题解直接贴ByVoid的吧,太神了:htt ...
- BZOJ-1061 志愿者招募 线性规划转最小费用最大流+数学模型 建模
本来一眼建模,以为傻逼题,然后发现自己傻逼...根本没想到神奇的数学模型..... 1061: [Noi2008]志愿者招募 Time Limit: 20 Sec Memory Limit: 162 ...
- BZOJ 1061: [Noi2008]志愿者招募 费用流
1061: [Noi2008]志愿者招募 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=1061 Description 申奥成功后,布布 ...
- 【费用流】NOI2008志愿者招募
1061: [Noi2008]志愿者招募 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 5171 Solved: 3089[Submit][Stat ...
- BZOJ 1061 志愿者招募(最小费用最大流)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1061 题意:申奥成功后,布布经过不懈努力,终于 成为奥组委下属公司人力资源部门的主管.布 ...
随机推荐
- Openwrt挂载NTFS硬盘提示“只读”错误的解决方法!
Openwrt是基于Linux代码编写,只支持NTFS格式硬盘的只读权限,否则当挂载的NTFS硬盘写入超过2M左右,就会出现"error:read-only file system" ...
- Android 四大组件学习之Service五
本节学习IntentService, 可能就有人问了. 什么是IntentService, IntentService有什么作用? 不是已经有了Service,那为什么还要引入IntentServic ...
- break return continue
1.return 语句的作用 (1) return 从当前的方法中退出,返回到该调用的方法的语句处,继续执行 (2) return 返回一个值给调用该方法的语句,返回值的数据类型必须与方法的声明中的返 ...
- net start sshd 发生系统错误1069--cygwin安装过程
net start sshd 发生系统错误1069 解决方法: services.msc调出服务,然后CYGWIN sshd服务->属性,修改账户的名字和密码(win7的登录名和密码) 可能还遇 ...
- 较大主干网的ISP通常控制信道利用率不超过50%
信道利用率 网络利用率 加权平均值
- 滑动窗体的最大值(STL的应用+剑指offer)
滑动窗体的最大值 參与人数:767时间限制:1秒空间限制:32768K 通过比例:21.61% 最佳记录:0 ms|8552K(来自 ) 题目描写叙述 给定一个数组和滑动窗体的大小.找出全部滑动窗体里 ...
- The android gradle plugin version 2.3.0-beta2 is too old, please update to the latest version.
编译项目的时候,报如下错误: Error:(, ) A problem occurred evaluating project ':app'. > Failed to apply plugin ...
- YTU 1003: Redraiment的遭遇
1003: Redraiment的遭遇 时间限制: 1000 Sec 内存限制: 128 MB 提交: 198 解决: 71 题目描述 Redraiment的老家住在工业区,日耗电量非常大.是政府 ...
- Expression Blend实例中文教程(8) - 动画设计快速入门StoryBoard http://silverlightchina.net/html/tips/2010/0329/934.html
Expression Blend实例中文教程(8) - 动画设计快速入门StoryBoard 时间:2010-03-29 11:13来源:SilverlightChina.Net 作者:jv9 点击: ...
- Eclipse 插件管理
查看已安装的插件: [help]⇒ [About Eclipse]⇒ [Installed Softwares] 1. 常用插件 maven:安装步骤如下: [help]⇒ [Install new ...