最小费用最大流..乱搞即可

------------------------------------------------------------------------------

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
 
#define rep( i, n ) for( int i = 0; i < n; ++i )
#define Rep( i, n ) for( int i = 1; i <= n; ++i )
#define clr( x, c ) memset( x, c, sizeof( x ) )
  

using namespace std;

 
const int maxn = 50 + 5;
 
struct edge {
int to, cap, cost;
edge *next, *rev;
};
 
edge *head[ maxn ], *p[ maxn ];
edge* pt;
edge EDGE[ maxn << 3 ];
 
void init() {
pt = EDGE;
clr( head, 0 );
}
 
inline void add( int u, int v, int d, int w ) {
pt->to = v;
pt->cap = d;
pt->cost = w;
pt->next = head[ u ];
head[ u ] = pt++;
}
 
inline void add_edge( int u, int v, int d, int w ) {
add( u, v, d, w );
add( v, u, 0, -w );
head[ u ]->rev = head[ v ];
head[ v ]->rev = head[ u ];
}
 
int d[ maxn ], a[ maxn ];
bool inQ[ maxn ];
 
int minCost( int S, int T ) {
const int inf = 0x3f3f3f3f;
int flow = 0, cost = 0;
for( ; ; ) {
clr( inQ, 0 );
clr( d, inf );
d[ S ] = 0;
inQ[ S ] = 1;
a[ S ] = inf;
queue< int > Q;
Q.push( S );
while( !Q.empty() ) {
int x = Q.front(); Q.pop();
inQ[ x ] = 0;
for( edge* e = head[ x ]; e; e = e->next )
   if( e->cap > 0 && d[ e->to ] > d[ x ] + e->cost ) {
    int to = e->to;
    d[ to ] = d[ x ] + e->cost;
    a[ to ] = min( a[ x ], e->cap );
    p[ to ] = e;
    if( !inQ[ to ] )
       Q.push( to ), inQ[ to ] = 1;
   }
}
if( d[ T ] == inf ) break;
flow += d[ T ];
cost += d[ T ] * a[ T ];
int x = T;
while( x != S) {
p[ x ]->cap -= a[ T ];
p[ x ]->rev->cap += a[ T ];
x = p[ x ]->rev->to;
}
}
return cost;
}
 
const int INF = 0x7fffffff;
 
int main() {
freopen( "test.in", "r", stdin );
int n, m, V;
cin >> n >> m >> V;
int s = 0, t = n + 1;
init();
Rep( i, n ) {
int x;
scanf( "%d", &x );
add_edge( i, t, x, 0 );
}
Rep( i, n ) {
int x;
scanf( "%d", &x );
add_edge( s, i, INF, x );
}
Rep( i, n - 1 )
   add_edge( i, i + 1, V, m );
cout << minCost( s, t ) << "\n";
return 0;
}

------------------------------------------------------------------------------

2424: [HAOI2010]订货

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 603  Solved: 394
[Submit][Status][Discuss]

Description

某公司估计市场在第i个月对某产品的需求量为Ui,已知在第i月该产品的订货单价为di,上个月月底未销完的单位产品要付存贮费用m,假定第一月月初的库存量为零,第n月月底的库存量也为零,问如何安排这n个月订购计划,才能使成本最低?每月月初订购,订购后产品立即到货,进库并供应市场,于当月被售掉则不必付存贮费。假设仓库容量为S。

Input

第1行:n, m, S (0<=n<=50, 0<=m<=10, 0<=S<=10000)
第2行:U1 , U2 , ... , Ui , ... , Un (0<=Ui<=10000)
第3行:d1 , d2 , ..., di , ... , dn (0<=di<=100)

Output

只有1行,一个整数,代表最低成本

Sample Input

3 1 1000
2 4 8
1 2 4

Sample Output

34

HINT

Source

BZOJ 2424: [HAOI2010]订货(最小费用最大流)的更多相关文章

  1. BZOJ 2424: [HAOI2010]订货(费用流)

    裸的费用流了= =从源点向每个点连费用为di,从汇点向每个点连流量为ui,每个点向下一个点连费用为m,流量为s的边就行了 CODE: #include<cstdio>#include< ...

  2. bzoj 2424: [HAOI2010]订货 (费用流)

    直接费用流,天数就是点数 type arr=record toward,next,cap,cost:longint; end; const maxm=; maxn=; mm=<<; var ...

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

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

  4. BZOJ 2424: [HAOI2010]订货

    2424: [HAOI2010]订货 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 915  Solved: 639[Submit][Status][ ...

  5. BZOJ 1927 星际竞速(最小费用最大流)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1927 题意:一个图,n个点.对于给出的每条边 u,v,w,表示u和v中编号小的那个到编号 ...

  6. 2424. [HAOI2010]订货【费用流】

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

  7. BZOJ 1070: [SCOI2007]修车 [最小费用最大流]

    1070: [SCOI2007]修车 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 4936  Solved: 2032[Submit][Status] ...

  8. bzoj 1061 志愿者招募(最小费用最大流)

    [Noi2008]志愿者招募 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 3792  Solved: 2314[Submit][Status][Di ...

  9. BZOJ 3550 Vacation(最小费用最大流)

    题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3550 题意:给出3×n个数字,从中选出一些数字,要求每连续的n个数字中选出的数字个 ...

随机推荐

  1. nginx 通过rsyslog发日志 rsyslog服务器挂掉 日志丢失问题

    nginx 配置: user nginx; worker_processes 1; syslog local5 nginx-zjzc01; rsyslog 服务器收到的消息: -rw-r--r-- 1 ...

  2. 2016 Multi-University Training Contest 8 总结

    回家之后一堆的事情,最后两场多校都没怎么参加,终于现在有些时间可以把第八场的总结补上. 欣君开局看出06题公式,我照着写,一A,差一分钟拿到FB,有点可惜. 磊哥觉得11题水题,写了一下,一A. 欣君 ...

  3. CF 293 E Close Vertices (树的分治+树状数组)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题目:给出一棵树,问有多少条路径权值和不大于w,长 ...

  4. jstack命令使用

    概述 jstack可用于导出java运用程序的线程堆栈.其基本使用语法为: jstack [-l] pid -l 选项用于打印锁的额外信息. 使用演示样例 以下这段代码执行之后会出现死锁现象(由于线程 ...

  5. Android的MVC框架

    http://www.cnblogs.com/wanghafan/archive/2012/07/20/2600786.html MVC是当前比较流行的框架,随便Google下,就可以发现几乎所有的应 ...

  6. iOS点滴- ViewController详解

    一.生命周期 当一个视图控制器被创建,并在屏幕上显示的时候. 代码的执行顺序 1. alloc                              创建对象,分配空间 2.init (initW ...

  7. mvc下载文件

    MVC下载文件方式 方式一: public FileStreamResult DownFile(string filePath, string fileName)  {       string ab ...

  8. 利用Telnet来模拟Http请求 有GET和POST两种

    利用Telnet来模拟Http请求---访问百度.       1.打开"运行"->cmd进入命令环境:       2.输入"telnet www.baidu.c ...

  9. T-SQL语句中中括号([])的用法是什么,什么时候该用

    加了[]是为了防止歧义,使计算机能识别.有些字段可能是关键字,这时候你直接用字段名就会报错,如果加了[]就可以正常执行了

  10. EL表达式中引用隐式变量

    除了在jsp中9大隐式变量(在前面文章也叫预定义变量)在转化成为servlet后_jspService中可以看到: public void _jspService(final javax.servle ...