BZOJ 2424: [HAOI2010]订货(费用流)
裸的费用流了= =从源点向每个点连费用为di,从汇点向每个点连流量为ui,每个点向下一个点连费用为m,流量为s的边就行了
CODE:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define maxn 65
#define maxm 400
#define inf 0x7fffffff
struct edges{
int to,next,cap,dist;
}edge[maxm];
int next[maxn],l;
int s,t;
int addedge(int x,int y,int z,int cap){
l++;
edge[l*2]=(edges){y,next[x],cap,z};
edge[l*2+1]=(edges){x,next[y],0,-z};
next[x]=l*2;next[y]=l*2+1;
return 0;
}
int dist[maxn],way[maxn];
bool b[maxn];
queue<int> q;
bool spfa(){
for (int i=1;i<=t;i++) dist[i]=inf;
dist[s]=0;
q.push(s);
while (!q.empty()){
int u=q.front();q.pop();
b[u]=0;
for (int i=next[u];i;i=edge[i].next)
if (edge[i].cap&&dist[edge[i].to]>dist[u]+edge[i].dist){
dist[edge[i].to]=dist[u]+edge[i].dist;
way[edge[i].to]=i;
if(!b[edge[i].to]){
b[edge[i].to]=1;
q.push(edge[i].to);
}
}
}
if (dist[t]==inf) return 0;
return 1;
}
int mcmf(){
int cost=0;
while (spfa()){
int flow=inf,x=t;
while (x!=s){
flow=min(flow,edge[way[x]].cap);
x=edge[way[x]^1].to;
}
cost+=dist[t]*flow;
x=t;
while (x!=s){
edge[way[x]].cap-=flow;
edge[way[x]^1].cap+=flow;
x=edge[way[x]^1].to;
}
}
return cost;
}
int main(){
int n,m,S;
scanf("%d%d%d",&n,&m,&S);
s=n+1;t=n+2;
for (int i=1;i<n;i++) addedge(i,i+1,m,S);
for (int i=1;i<=n;i++) {
int x;
scanf("%d",&x);
addedge(i,t,0,x);
}
for (int i=1;i<=n;i++) {
int x;
scanf("%d",&x);
addedge(s,i,x,inf);
}
printf("%d",mcmf());
return 0;
}
BZOJ 2424: [HAOI2010]订货(费用流)的更多相关文章
- BZOJ 2424: [HAOI2010]订货 费用流
2424: [HAOI2010]订货 Description 某公司估计市场在第i个月对某产品的需求量为Ui,已知在第i月该产品的订货单价为di,上个月月底未销完的单位产品要付存贮费用m,假定第一月月 ...
- BZOJ 2424: [HAOI2010]订货(最小费用最大流)
最小费用最大流..乱搞即可 ------------------------------------------------------------------------------ #includ ...
- BZOJ 2424: [HAOI2010]订货
2424: [HAOI2010]订货 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 915 Solved: 639[Submit][Status][ ...
- bzoj 2424: [HAOI2010]订货 (费用流)
直接费用流,天数就是点数 type arr=record toward,next,cap,cost:longint; end; const maxm=; maxn=; mm=<<; var ...
- 【bzoj2424】[HAOI2010]订货 费用流
原文地址:http://www.cnblogs.com/GXZlegend/p/6825296.html 题目描述 某公司估计市场在第i个月对某产品的需求量为Ui,已知在第i月该产品的订货单价为di, ...
- BZOJ2424 [HAOI2010]订货 - 费用流
题解 (非常裸的费用流 题意有一点表明不清: 该月卖出的商品可以不用算进仓库里面. 然后套上费用流模板 代码 #include<cstring> #include<queue> ...
- BZOJ 2424 DP OR 费用流
思路: 1.DP f[i][j]表示第i个月的月底 还剩j的容量 转移还是相对比较好想的-- f[i][j+1]=min(f[i][j+1],f[i][j]+d[i]); if(j>=u[i+1 ...
- 2424: [HAOI2010]订货
2424: [HAOI2010]订货 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 922 Solved: 642[Submit][Status][ ...
- [bzoj 1449] 球队收益(费用流)
[bzoj 1449] 球队收益(费用流) Description Input Output 一个整数表示联盟里所有球队收益之和的最小值. Sample Input 3 3 1 0 2 1 1 1 1 ...
随机推荐
- mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: YES)'
就当作自己忘记Mysql密码把,忘记密码的解决方法 一.mysql登录错误mysqladmin: connect to server at 'localhost' failederror: 'Acce ...
- Led控件
在 WindowMobile 上的模拟LED 显示屏插件 一个简单Led控件 一个经典的控制Led的单片机程序 Led控件(2)——Led显示屏模拟
- JavaScript------处理Json数据
//JSON相关函数 JSON.parse(); //将JSON字符串转换为JavaScript对象JSON.stringify(); //将JavaScript值转换为JSON字符串 1.//JSO ...
- 在MVC中添加拦截器实现登录后的权限验证
1.新建一个类 (以下实现了打印日志功能) using System; using System.Collections.Generic; using System.Linq; using Syste ...
- pku2104
传送门:http://poj.org/problem?id=2104 题目大意:给定一个长度为N的数组{A[i]},你的任务是解决Q个询问.每次询问在A[l], A[l+1], ...... , A[ ...
- bzoj1070————2016——3——14
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1070: 题目概括: Description 同一时刻有N位车主带着他们的爱车来到了汽车维修中 ...
- 移动硬盘/U盘装Windows 7旗舰版(VHD版)
真正的移动版WIN7,在移动硬盘/U盘上运行的WIN7 工具准备 - 联想Y450本本,已安装Windows 7旗舰版(或者WINPE3.0版),用来给移动WIN7做引导 -Win7.vhd,15G, ...
- Bootstrap每天必学之导航条
http://www.jb51.net/article/75534.htm Bootstrap每天必学之导航条,本文向大家讲解了多种多样的导航条,以及导航条中元素的实现方法,感兴趣的小伙伴们可以参考一 ...
- Angular - - $sce 和 $sceDelegate
$sce $sce 服务是AngularJs提供的一种严格上下文转义服务. 严格的上下文转义服务 严格的上下文转义(SCE)是一种需要在一定的语境中导致AngularJS绑定值被标记为安全使用语境的模 ...
- 位运算,算术、逻辑运算详解-java篇
/** * 功能: * 位运算符,原码.反码.补码规则: * 1.二进制的最高位是符号位:0表示正数,1表示负数 * 2.正数的原码.反码.补码都一样 * 3.负数的反码=它的原码符号位不变,其他位取 ...