题解

(非常裸的费用流

题意有一点表明不清: 该月卖出的商品可以不用算进仓库里面。

然后套上费用流模板

代码

 #include<cstring>
#include<queue>
#include<cstdio>
#include<algorithm>
#define rd read()
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
using namespace std; const int N = 1e4;
const int inf = ; int n, m, maxin;
int nd[N], cost[N], head[N], tot, S, T = N - , maxflow, minco;
int dis[N], pre[N], vis[N]; queue<int> q; struct edge {
int nxt, val, to, c;
}e[N]; int read() {
int X = , p = ; char c = getchar();
for(; c > '' || c < ''; c = getchar()) if(c == '-') p = -;
for(; c >= '' && c <= ''; c = getchar()) X = X * + c - '';
return X * p;
} int ch(int x) {
return ( (x + ) ^ ) - ;
} void added(int fr, int to, int val, int c) {
e[++tot].to = to;
e[tot].val = val;
e[tot].c = c;
e[tot].nxt = head[fr];
head[fr] = tot;
} void add(int fr, int to, int val, int c) {
added(fr, to, val, c);
added(to, fr, , -c);
} int bfs() {
memset(dis, , sizeof(dis));
memset(vis, , sizeof(vis));
memset(pre, , sizeof(pre));
dis[S] = ;
vis[S] = ;
q.push(S);
for(int u, nt; !q.empty(); ) {
u = q.front(); q.pop();
for(int i = head[u]; i; i = e[i].nxt ) {
nt = e[i].to;
if(dis[nt] <= dis[u] + e[i].c || !e[i].val) continue;
dis[nt] = dis[u] + e[i].c;
pre[nt] = i;
if(!vis[nt]) vis[nt] = , q.push(nt);
}
vis[u] = ;
}
return dis[T];
} void EK() {
for(; bfs() != inf; ) {
int tmp = inf;
for(int i = pre[T]; i; i = pre[e[ch(i)].to]) tmp = min(tmp, e[i].val);
for(int i = pre[T]; i; i = pre[e[ch(i)].to]) e[i].val -= tmp, e[ch(i)].val += tmp;
maxflow += tmp;
minco += tmp * dis[T];
}
} int main()
{
n = rd; m = rd; maxin = rd;
rep(i, , n) nd[i] = rd;
rep(i, , n) cost[i] = rd;
rep(i, , n) {
add(S, i, inf, cost[i]);
add(i, T, nd[i], );
add(i, i + , maxin, m);
}
EK();
printf("%d\n", minco);
}

BZOJ2424 [HAOI2010]订货 - 费用流的更多相关文章

  1. 【bzoj2424】[HAOI2010]订货 费用流

    原文地址:http://www.cnblogs.com/GXZlegend/p/6825296.html 题目描述 某公司估计市场在第i个月对某产品的需求量为Ui,已知在第i月该产品的订货单价为di, ...

  2. BZOJ 2424: [HAOI2010]订货 费用流

    2424: [HAOI2010]订货 Description 某公司估计市场在第i个月对某产品的需求量为Ui,已知在第i月该产品的订货单价为di,上个月月底未销完的单位产品要付存贮费用m,假定第一月月 ...

  3. bzoj2424 [HAOI2010]订货 dp+单调性

    [HAOI2010]订货 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1311  Solved: 884[Submit][Status][Discu ...

  4. BZOJ-2424: [HAOI2010]订货【费用流】

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1487  Solved: 1002[Submit][Status][Discuss] Descript ...

  5. [HAOI2010][bzoj2424] 订货 [费用流]

    题面 传送门 思路 这题其实挺水的......做过餐巾计划问题就能明白,是同一个道理 首先,显然刚刚好满足每一个月的需求,会得到最优解(废话-_-||) 然后我们发现,货物在不同的月之间的转移,可以比 ...

  6. bzoj2424 [HAOI2010]订货

    模拟一下仓库里面存储物品的价格情况即可,如果当前物品大于仓库里面物品那么就替换一下仓库里的物品,然后订货直接从仓库里先取,仓库里不够则直接购买,每次做完后记得买当前物品填补一下仓库直至仓库填满,当然这 ...

  7. 【BZOJ2424】[HAOI2010]订货(费用流)

    [BZOJ2424][HAOI2010]订货(费用流) 题面 BZOJ 洛谷 题解 傻逼费用流吧... 一开始理解错意思了,仓库大小为\(m\)的含义是留到下个月最多为\(m\),而不是任意时刻的容量 ...

  8. BZOJ 2424: [HAOI2010]订货(最小费用最大流)

    最小费用最大流..乱搞即可 ------------------------------------------------------------------------------ #includ ...

  9. BZOJ_2424_[HAOI2010]订货_最小费用最大流

    BZOJ_2424_[HAOI2010]订货_最小费用最大流 Description 某公司估计市场在第i个月对某产品的需求量为Ui,已知在第i月该产品的订货单价为di,上个月月底未销完的单位产品要付 ...

随机推荐

  1. Mongodb下载、安装、配置与使用

    记得在管理员模式下运行CMD,否则服务将启动失败 一.下载 官网下载地址:https://www.mongodb.com/download-center?jmp=nav#community 为了方便下 ...

  2. 两个栈实现队列 Python实现

    # coding=utf-8 MAX_LENGTH = 100 SUCCESS = 1 FAIL = 0 ERROR = -1 class Queue(object): stack_fir = Non ...

  3. MyBatis 中#与$的区别

    今天在工作中有个点击排序的功能调试了许久,终寻因,总结之.  需求是这样的,页面有个table,有一列的上下箭头可点击并排序.对于这种需求,我的mybatis.xml的sql配置写成了如下: < ...

  4. ORM sqlachemy学习

    内容: 1.ORM介绍 2.SQLAlchemy介绍 3.SQLAlchemy内部处理 4.SQLAlchemy使用 参考: http://www.cnblogs.com/wupeiqi/articl ...

  5. uva-10474-枚举-水题

    题意:看代码 #include<stdio.h> #include<iostream> #include<sstream> #include<queue> ...

  6. checkbox的美化(转)

    http://www.w3cfuns.com/blog-5422889-5398674.html <!DOCTYPE html> <html> <head> < ...

  7. POI 生成带联动下拉框的excel表格

    参考:https://www.cnblogs.com/cjbbk/p/7527276.html 解决POI3.17 与其它版本的不同的坑:https://blog.csdn.net/Weirdo_zh ...

  8. 5.mybatis实战教程(mybatis in action)之五:与spring3集成(附源码)

    转自:https://blog.csdn.net/nnn9223643/article/details/41962097 在 这一系列文章中,前面讲到纯粹用mybatis 连接数据库, 然后 进行增删 ...

  9. FMX ScrollBox 拖拽控制

    Firemonkey下的ScrollBox 拖拽控制,滚动控制,拖拽,滚动条 AniCalculations 仅允许纵向拖拽,拖拽 scrlbx.AniCalculations.TouchTracki ...

  10. IOS CFBundleIdentifier

    CFBundleIdentifier  CFBundleIdentifier 必须是com.12306.aaa 这样的格式吗       AppID   用通配符格式的AppID方便.   AppSt ...