以前写的1061但一直没懂,后来懂了但忘写解题报告了

做了1283顺便补一下吧

1061 我是orz https://www.byvoid.com/blog/noi-2008-employee/#more-916

这类类似线性规划的费用流构造,大概有这么几个步骤

首先找出不等式约束关系,然后添加辅助变量变成等式,并写出目标函数

然后通过做差构造,使每个变量都出现在两个等式中

每个等式整理成变量+常量=0 根据入流=出硫,我们把每个等式作为一个点

如果我们把等式左边系数为正作为入流,系数为负作为出流

则,对于每个变量,如果在等式j出现时系数为正,等式k系数为-,则k向j连边 流量为无穷,费用由目标函数决定

如果是常量,正则源点向这个等式连边,负则其向汇点连边,流量为常量的绝对值

然后我们就可以跑费用流了

 const inf=;

 type node=record
next,point,flow:longint;
cost:int64;
end; var edge:array[..] of node;
c,p,cur,pre:array[..] of longint;
d:array[..] of int64;
v:array[..] of boolean;
q:array[..] of longint;
b,e,w,i,j,n,m,len,t:longint;
ans:int64; procedure add(x,y,f:longint;w:int64);
begin
inc(len);
edge[len].point:=y;
edge[len].flow:=f;
edge[len].cost:=w;
edge[len].next:=p[x];
p[x]:=len;
end; function spfa:boolean;
var f,r,x,y,i:longint;
begin
f:=;
r:=;
q[]:=;
for i:= to t do
d[i]:=inf;
fillchar(v,sizeof(v),false);
v[]:=true;
while f<=r do
begin
x:=q[f];
v[x]:=false;
i:=p[x];
while i<>- do
begin
y:=edge[i].point;
if edge[i].flow> then
if d[y]>d[x]+edge[i].cost then
begin
d[y]:=d[x]+edge[i].cost;
pre[y]:=x;
cur[y]:=i;
if not v[y] then
begin
inc(r);
q[r]:=y;
v[y]:=true;
end;
end;
i:=edge[i].next;
end;
inc(f);
end;
if d[t]=inf then exit(false) else exit(true);
end; procedure mincost;
var i,j:longint;
neck:int64;
begin
while spfa do
begin
neck:=inf;
i:=t;
while i<> do
begin
j:=cur[i];
if edge[j].flow<neck then neck:=edge[j].flow;
i:=pre[i];
end;
i:=t;
while i<> do
begin
j:=cur[i];
dec(edge[j].flow,neck);
inc(edge[j xor ].flow,neck);
i:=pre[i];
end;
ans:=ans+d[t]*neck;
end;
end; begin
readln(n,m);
len:=-;
fillchar(p,sizeof(p),);
t:=n+;
for i:= to n do
read(c[i]);
for i:= to m do
begin
readln(b,e,w);
add(b,e+,inf,w);
add(e+,b,,-w);
end;
for i:= to n+ do
begin
w:=c[i]-c[i-];
if w>= then
begin
add(,i,w,);
add(i,,-w,);
end
else begin
add(i,t,-w,);
add(t,i,,);
end;
if i> then
begin
add(i,i-,inf,);
add(i-,i,,);
end;
end;
mincost;
writeln(ans);
end.

1061

 type node=record
po,next,flow,cost:longint;
end; var e:array[..] of node;
d,pre,cur,p:array[..] of longint;
v:array[..] of boolean;
q:array[..] of longint;
i,x,y,n,m,len,t,k:longint; procedure add(x,y,f,c:longint);
begin
inc(len);
e[len].po:=y;
e[len].flow:=f;
e[len].cost:=c;
e[len].next:=p[x];
p[x]:=len;
end; procedure build(x,y,f,c:longint);
begin
add(x,y,f,c);
add(y,x,,-c);
end; function spfa:boolean;
var i,f,r,x,y:longint;
begin
fillchar(v,sizeof(v),false);
for i:= to t do
d[i]:=-;
d[]:=;
f:=;
r:=;
q[]:=;
while f<=r do
begin
x:=q[f];
v[x]:=false;
i:=p[x];
while i<>- do
begin
y:=e[i].po;
if e[i].flow> then
if d[y]<d[x]+e[i].cost then
begin
d[y]:=d[x]+e[i].cost;
pre[y]:=x;
cur[y]:=i;
if not v[y] then
begin
inc(r);
q[r]:=y;
v[y]:=true;
end;
end;
i:=e[i].next;
end;
inc(f);
end;
if d[t]<= then exit(false) else exit(true);
end; function maxcost:longint;
var i,j:longint;
begin
maxcost:=;
while spfa do
begin
i:=t;
while i<> do
begin
j:=cur[i];
dec(e[j].flow);
inc(e[j xor ].flow);
i:=pre[i];
end;
maxcost:=maxcost+d[t];
end;
end; begin
readln(n,m,k);
len:=-;
fillchar(p,sizeof(p),);
t:=n+;
for i:= to n do
begin
read(x);
y:=i+m;
if y>n then y:=t;
build(i,y,,x);
build(i,i+,k,);
end;
build(,,k,);
writeln(maxcost);
end.

1283

UPD:这种题目可以直接跑单纯形

但是为什么单纯形能保证用最优解一定是整数呢,求神犇教导

bzoj1061 1283的更多相关文章

  1. 【bzoj1061】 Noi2008—志愿者招募

    http://www.lydsy.com/JudgeOnline/problem.php?id=1061 (题目链接) 题意 给定n天,第i天需要ai个志愿者,有m类志愿者,每类志愿者工作时间为[l, ...

  2. [BZOJ1061][Noi2008]志愿者招募

    [BZOJ1061][Noi2008]志愿者招募 试题描述 申奥成功后,布布经过不懈努力,终于成为奥组委下属公司人力资源部门的主管.布布刚上任就遇到了一个难 题:为即将启动的奥运新项目招募一批短期志愿 ...

  3. hiho #1283 hiho密码 [Offer收割]编程练习赛3

    #1283 : hiho密码 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho根据最近在密码学课上学习到的知识,开发出了一款hiho密码,这款密码的秘钥是这样生成的 ...

  4. ural 1283. Dwarf

    1283. Dwarf Time limit: 1.0 secondMemory limit: 64 MB Venus dwarfs are rather unpleasant creatures: ...

  5. 九度OJ 1283 第一个只出现一次的字符

    题目地址:http://ac.jobdu.com/problem.php?pid=1283 题目描述: 在一个字符串(1<=字符串长度<=10000,全部由大写字母组成)中找到第一个只出现 ...

  6. bzoj1061 志愿者招募

    bzoj1061 志愿者招募 Description 申奥成功后,布布经过不懈努力,终于成为奥组委下属公司人力资源部门的主管.布布刚上任就遇到了一个难 题:为即将启动的奥运新项目招募一批短期志愿者.经 ...

  7. codevs 1283 等差子序列

    http://codevs.cn/problem/1283/ 题目描述 Description 给一个 1 到 N 的排列{Ai},询问是否存在 1<=p1<p2<p3<p4& ...

  8. 网络流解线性规划问题 BZOJ1061: [Noi2008]志愿者招募

    线性规划定义: 在给定有限的资源和竞争约束情况下,很多问题都可以表述为最大化或最小化某个目标.如果可以把目标指定为某些变量的线性函数,而且如果可以将资源约束指定为这些变量的等式或不等式,则得到了一个线 ...

  9. bzoj 1283 序列 - 费用流

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求选出一些数使得原序列中每$m$个连续的数中不超过$K$个被选走.问最大的可能的和. 感觉建图好妙啊.. 考虑把问题转化成选$m$次数,每次 ...

随机推荐

  1. Python的注释

    任何时候,我们都可以给程序加上注释.注释是用来说明代码的,给自己或别人看,而程序运行的时候,Python解释器会直接忽略掉注释,所以,有没有注释不影响程序的执行结果,但是影响到别人能不能看懂你的代码. ...

  2. 用火狐打开PDF文件

    可以直接使用官方的Adobe Reader插件来实现在火狐中浏览PDF文件的功能.在你浏览一个PDF文件的时候,火狐将会尝试下载安装这个插件. 如果这个插件出现问题,那么就无计可施啦. 检查火狐的设置 ...

  3. Many To one 多对一

    一.创建实体类:多方存一方的对象.set/get 二.编写对象的xml文件 别忘记在confg.xml映射! 三.编写接口 四.方法测试

  4. CSS两列及三列自适应布局方法整理

    布局 自适应 两列 三列 在传统方法的基础上加入了Flex布局并阐述各方法的优缺点,希望对大家有所帮助.先上目录: 两列布局:左侧定宽,右侧自适应 方法一:利用float和负外边距 方法二:利用外边距 ...

  5. springmvc 数据对象回绑

    springmvc中,由页面 post到 controller,对象可以在form里面设置modelAttribute达到回绑的目的. 但是如果对象里面有复杂的非String,int的对象,则要在co ...

  6. 2326: [HNOI2011]数学作业 - BZOJ

    首先是DP,分段DP(按位数讨论) 然后每一段构造出它对应的矩阵,用矩阵快速幂加速 type matrix=..,..]of int64; var n,m:int64; a,b,c,d:matrix; ...

  7. 1055: [HAOI2008]玩具取名 - BZOJ

    Description 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后他会根据自己的喜好,将名字中任意一个字母用“WING”中任意两个字母代替,使 ...

  8. javascript中跨源资源共享

    来自<javascript高级程序设计 第三版:作者Nicholas C. Zakas>的学习笔记(十) 通过XHR实现Ajax通信的一个主要限制,来源于跨域安全策略.默认情况下,XHR对 ...

  9. TIANKENG’s restaurant

    Problem B:http://codeforces.com/contest/616/problem/B B. Dinner with Emma 题意:一对夫妻要去餐厅吃晚饭,Emma 想去最豪华( ...

  10. spoj 95

    栈应用 ...... 水题 #include<cstdio> #include<cstdlib> #include<cstring> #include<alg ...