BZOJ-2424: [HAOI2010]订货【费用流】
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 1487 Solved: 1002
[Submit][Status][Discuss]
Description
Input
Output
只有1行,一个整数,代表最低成本
Sample Input
2 4 8
1 2 4
Sample Output
HINT
Source
思路:建立超级源和超级汇,令每条连向超级汇的边代价为0、cap为当月需求量,连向超级源的边cap无穷大,代价为当月进货价,每月之间连的边cap为仓库容量,代价为每天贮存花销。
建图后跑MCMF
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
const int maxn = ;
const int inf = 0x3f3f3f3f; int n,m,s;
int cnt = ;
int ans;
int from[],q[],dis[],head[];
bool inq[]; template<class T>inline void read(T &res)
{
char c;T flag=;
while((c=getchar())<''||c>'')if(c=='-')flag=-;res=c-'';
while((c=getchar())>=''&&c<='')res=res*+c-'';res*=flag;
} struct node {
int from,to,next,v,c;
}e[]; void add(int u,int v,int w,int c)
{
cnt++;
e[cnt].from = u;
e[cnt].to = v;
e[cnt].v = w;
e[cnt].c = c;
e[cnt].next = head[u];
head[u] = cnt;
} void BuildGraph(int u,int v,int w,int c)
{
add(u,v,w,c);
add(v,u,,-c);///反向
} bool spfa()
{
for(int i = ; i <= maxn; i++)dis[i]=inf;
int t = , w = , now;
dis[] = q[] = ;
inq[] = ;
while(t != w) {
now = q[t];
t++;
if(t == maxn) t = ;
for(int i = head[now]; i; i = e[i].next) {
if(e[i].v && dis[e[i].to] > dis[now] + e[i].c) {
from[e[i].to] = i;
dis[e[i].to] = dis[now] + e[i].c;
if(!inq[e[i].to]) {
inq[e[i].to] = ;
q[w++] = e[i].to;
if(w == maxn) w = ;
}
}
}
inq[now] = ;
}
if(dis[maxn] == inf)
return ;
return ;
} void mcmf()///最小费用最大流
{
int i;
int x = inf;
i = from[maxn];
while(i) {
x = min(e[i].v,x);
i = from[e[i].from];
}
i = from[maxn];
while(i) {
e[i].v -= x;
e[i^].v += x;
ans += x * e[i].c;
//printf("ans : %d\n",ans);
i = from[e[i].from];
}
} int main()
{
read(n),read(m),read(s);
for(int i = ; i <= n; i++) {
int u;
read(u);
BuildGraph(i, maxn, u, );
}
for(int i = ; i <= n; i++) {
int d;
read(d);
BuildGraph(, i, inf, d);
}
for(int i = ; i < n; i++) {
BuildGraph(i, i+, s, m);
}
while(spfa()) {
mcmf();
}
printf("%d",ans);
return ;
}
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]订货(费用流)
裸的费用流了= =从源点向每个点连费用为di,从汇点向每个点连流量为ui,每个点向下一个点连费用为m,流量为s的边就行了 CODE: #include<cstdio>#include< ...
- 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 ...
随机推荐
- Arm开发板+Qt学习之路-qt线程执行完毕发送signal主动释放线程内存
header: #ifndef SENDCANMSGTHREAD_H#define SENDCANMSGTHREAD_H #include <QThread>#include " ...
- NCE L4
课文内容 重点单词详解 课文内容详解
- MySQL存储过程和游标
一.存储过程 什么是存储过程,为什么要使用存储过程以及如何使用存储过程,并且介绍创建和使用存储过程的基本语法. 什么是存储过程: 存储过程可以说是一个记录集,它是由一些T-SQL语句组成的代码块,这些 ...
- Windows CMD 输出文本到文件,不加换行符
>test.txt set /p="Hello" <nul >>test.txt set /p=" world!" <nul 正文 ...
- MySQL 的一条语句是怎么执行的
该文为< MySQL 实战 45 讲>的学习笔记,感谢查看,如有错误,欢迎指正 一.MySQL 的基础架构 以下就是 MySQL 的基础架构图. 在 Linux 中安装 MySQL 时,最 ...
- ansible基本使用(一)
ansible是什么? ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.chef.func.fabric)的优点,实现了批量系统配置.批量程序部署.批量 ...
- C# WPF从RIOT API获取数据(RIOT代表作品《英雄联盟》)
微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. C# WPF从RIOT API获取数据(RIOT代表作品<英雄联盟>) 阅读导航 ...
- vue ----element-ui 文件上传upload 组件 实现 及其后台
1.前台 action 不用改 :https://jsonplaceholder.typicode.com/posts/ getFile: 获取文件 data(){ return { file: {} ...
- cat - EOF标志的使用
前提 cat命令是用于连接文件并输出到标准输出设备或指定文件中. EOF为标志,可以替换为其他字符串 代码块 ``` 将文件内容作为标准输出也就是将文件内容输出到屏幕中,也可写作 cat filena ...
- 剑指offer-面试题51-数组中的逆序对-归并排序
/* 题目: 求给定数组的逆序对数. */ /* 思路: 归并排序. */ #include<iostream> #include<cstring> #include<v ...