裸的费用流了= =从源点向每个点连费用为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]订货(费用流)的更多相关文章

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

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

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

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

  3. BZOJ 2424: [HAOI2010]订货

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

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

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

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

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

  6. BZOJ2424 [HAOI2010]订货 - 费用流

    题解 (非常裸的费用流 题意有一点表明不清: 该月卖出的商品可以不用算进仓库里面. 然后套上费用流模板 代码 #include<cstring> #include<queue> ...

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

  8. 2424: [HAOI2010]订货

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

  9. [bzoj 1449] 球队收益(费用流)

    [bzoj 1449] 球队收益(费用流) Description Input Output 一个整数表示联盟里所有球队收益之和的最小值. Sample Input 3 3 1 0 2 1 1 1 1 ...

随机推荐

  1. PHPCMS快速建站系列之自定义分页函数

    内容分页的实现方法:{pc:content action="lists" catid="$catid" order="id DESC" nu ...

  2. PowerShell学习小结

    1. 获取所有别名信息Get-Alias 2. 获取指定别名信息Get-Alias xx 3. 通过command name获得指定别名信息Get-Alias -Definition xx-xxx 4 ...

  3. javascript---jquery (1事件)

    1.例子说明 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...

  4. Nodejs之目录介绍及app.js说明

    nodejs目录说明,app.js简单介绍及如何设置app.js启动项目. 新建的项目结构应该是这样 bin:项目的启动文件,也可以放其他脚本. node_modules:用来存放项目的依赖库. pu ...

  5. DEV组件LookupEdit,ComboBoxEdit绑定数据源

    LookupEdit可以绑定数据表(DataTable)或对象数据组(Object List)作为数据源,下拉窗体可自定显示栏位. 绑定数据源需要设置三个参数:DisplayMember ,Value ...

  6. 【WebStorm】前端工具开发利器webstrom专篇...更新中

    http://my.oschina.net/maomi/blog/137807#OSC_h2_5 WebStorm混搭svn WebStorm混搭nodeJS webstorm简单介绍 webstor ...

  7. Quartz2D 之 简单使用

    1. 获取Graphics Context CGContextRef ctx = UIGraphicsGetCurrentContext(); 2. 最后的渲染接口 CGContextStrokePa ...

  8. CSS图形形状大全

    The Shapes of CSS All of the below use only a single HTML element. Any kind of CSS goes, as long as ...

  9. PHP 绘图技术

    1.图片格式:目前网站开发常见的图片格式有gif,jpg/jpeg,png ..... 区别: gif 图片压缩率高,但是只能显示256色,可能造成颜色的丢失,可以显示动画 jpg/jpeg 图片压缩 ...

  10. iOS开发之内存缓存机制

    使用缓存的目的是为了使用的应用程序能更快速的响应用户输入,是程序高效的运行.有时候我们需要将远程web服务器获取的数据缓存起来,减少对同一个url多次请求. 内存缓存我们可以使用sdk中的NSURLC ...