【最小费用流】
来源:互联网 发布:js object 键 值 编辑:程序博客网 时间:2024/06/05 09:46
一、有时间再完善
const int INF=0x3f3f3f3f;const int MAXN=66;struct edge{ int to,cap,cost,rev; edge(int x,int y,int z,int w) { to=x;cost=y;cap=z;rev=w; }};vector<edge> g[MAXN];int prei[MAXN],prej[MAXN],dist[MAXN],n2;void add(int from,int to,int cost,int cap){ g[from].push_back(edge(to,cost,cap,g[to].size())); g[to].push_back(edge(from,-cost,0,g[from].size()-1));}int min_cost_flow(int s,int t,int f){ int res=0; while(f>0) { for(int i=0;i<=n2;i++) dist[i]=INF; dist[s]=0; bool update=true; while(update) { update=false; for(int i=0;i<=n2;i++) { if(dist[i]==INF)continue; for(int j=0;j<g[i].size();j++) { edge &e=g[i][j]; if(e.cap>0&&dist[e.to]>dist[i]+e.cost) { dist[e.to]=dist[i]+e.cost; prei[e.to]=i; prej[e.to]=j; update=true; } } } } if(dist[t]==INF)return -1; int d=f; for(int i=t;i!=s;i=prei[i]) { d=min(d,g[prei[i]][prej[i]].cap); } f-=d; res+=d*dist[t]; for(int i=t;i!=s;i=prei[i]) { edge &e=g[prei[i]][prej[i]]; e.cap-=d; g[i][e.rev].cap+=d; } } return res;}
阅读全文
0 0
- 最小费用最小流uva10746
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- 最小费用流模版
- 【最小费用最大流】
- 最小费用流
- 最小费用最大流
- 最小费用最大流
- Intervals----最小费用流
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- hdu1853 最小费用流
- hdu1533 最小费用流
- hdu3667 最小费用流
- 安装vmware-tools出现"what is the location of the "ifconfig"program on your machine?"
- 从零开始前端学习[14]:选择器的优先级
- 图像处理基本算法(汇总)以及实现
- SCUT Training 20170920 Problem D
- Day01 Static 自定义工具类
- 【最小费用流】
- 顺序表应用2:多余元素删除之建表算法
- 1.asp.net中的错误机制
- SQL中delete,truncate和drop的区别
- 接口回调机制理解
- 贪婪方法——最小生成树
- 爹地的实验:实验一: 数据结构实验一线性表的基本操作实现及其应用
- java学习第三天
- HDU 4740 The Donkey of Gui Zhou 暴力