题解

(非常裸的费用流

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

然后套上费用流模板

代码

 #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. ioi2016aliens

    /* 首先考虑点在直线的两边效果一样 于是转移到一边 之后发现当我们覆盖某些点时,有其他的一些点一定会被覆盖 我们找出所有必须覆盖的点 之后我们发现我们找到的这些点 将其按照x递增排序 那么y也是递增 ...

  2. 微信小程序教程系列

    微信小程序教程系列 来源:       https://blog.csdn.net/michael_ouyang/article/details/56846185 相关连接:http://blog.c ...

  3. uva579-简单计算题

    题意: 求分钟和时钟之间的夹角 解法:俩个夹角互减 AC:10ms #include<iostream> #include<functional> #include<qu ...

  4. UVA-575-水题-模拟

    题意: 按照这个公式模拟 10120skew = 1×(25 −1)+0×(24 −1)+1×(23 −1)+2×(22 −1)+0×(21 −1) = 31+0+7+6+0 = 44. #inclu ...

  5. 文件的编辑命令-echo/cat

    touch test.yaml echo "line1 line2" >> test.yaml cat test.yaml line1 line2 # 创建test.y ...

  6. 使用amaze ui模板全过程

    amaze ui基于gulp构建,所以现在安装gulp需要的环境,gulp使用npm安装,npm基于node.js 所以一切从node.js开始 1 下载对应的node.js 打开 https://n ...

  7. 1.scrapyd部署相关问题

    部署scrapy爬虫项目到6800上 启动scrapyd 出现问题 1: scrapyd-deloy -l  未找到相关命令 scrapyd-deploy -l 可以看到当前部署的爬虫项目,但是当我输 ...

  8. CENTOS 挂载ntfs移动硬盘

    参考网址: http://www.it610.com/article/3368930.htm (较全)http://blog.51cto.com/ultrasql/1927672

  9. leetcode100

    /** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNo ...

  10. vue深入了解组件——动态组件&异步组件

    一.在动态组件上使用 keep-alive 我们之前曾经在一个多标签的界面中使用 is 特性来切换不同的组件: <component v-bind:is="currentTabComp ...