HDOJ 4240 - Route Redundancy 最大流+DP...阅读理解...
来源:互联网 发布:阿里云 快照恢复 编辑:程序博客网 时间:2024/05/17 07:59
题意:
一个城市的道路是由很多个点和有向图构成的...现在要求一个比例为:从A点到B点的最大流/A到B的最大路径流量....
题解:
最大流就裸最大流...最大路径流量用dp来做.类似SPFA...
Program:
#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<math.h>#include<queue>#define MAXN 2005#define MAXM 20000005#define oo 1000000007#define ll long longusing namespace std; struct Dinic { struct node { int x,y,c,d,next; }line[MAXM]; int Lnum,_next[MAXN],dis[MAXN],dp[MAXN]; bool inqueue[MAXN]; void initial(int n) { for (int i=0;i<=n;i++) _next[i]=-1; Lnum=-1; } void addline(int x,int y,int c) { line[++Lnum].next=_next[x],_next[x]=Lnum; line[Lnum].x=x,line[Lnum].y=y,line[Lnum].c=line[Lnum].d=c; line[++Lnum].next=_next[y],_next[y]=Lnum; line[Lnum].x=y,line[Lnum].y=x,line[Lnum].c=line[Lnum].d=0; } bool BFS(int s,int e) { queue<int> Q; while (!Q.empty()) Q.pop(); memset(dis,0,sizeof(dis)); dis[s]=1,Q.push(s); while (!Q.empty()) { int h,k; h=Q.front(),Q.pop(); if (h==e) return dis[e]; for (k=_next[h];k!=-1;k=line[k].next) if (line[k].c && !dis[line[k].y]) dis[line[k].y]=dis[h]+1,Q.push(line[k].y); } return false; } int dfs(int x,int flow,int e) { if (x==e) return flow; int temp,cost=0; for (int k=_next[x];k!=-1;k=line[k].next) if (line[k].c && dis[line[k].y]==dis[x]+1) { temp=dfs(line[k].y,min(flow-cost,line[k].c),e); if (temp) { line[k].c-=temp,line[k^1].c+=temp; cost+=temp; if (flow==cost) return cost; }else dis[line[k].y]=-1; } return cost; } int MaxFlow(int s,int e) { int MaxFlow=0; while (BFS(s,e)) MaxFlow+=dfs(s,oo,e); return MaxFlow; } int DP(int s,int e) { queue<int> Q; while (!Q.empty()) Q.pop(); memset(dp,0,sizeof(dp)); dp[s]=oo,Q.push(s); memset(inqueue,false,sizeof(inqueue)); while (!Q.empty()) { int h=Q.front(); Q.pop(),inqueue[h]=false; for (int k=_next[h];k!=-1;k=line[k].next) { int y=line[k].y,t=min(dp[h],line[k].d); if (t>dp[y]) { dp[y]=t; if (!inqueue[y]) Q.push(y),inqueue[y]=true; } } } if (!dp[e]) return oo; return dp[e]; } }T; int main() { int P,D,N,M,S,E,x,y,c; scanf("%d",&P); while (P--) { scanf("%d%d%d%d%d",&D,&N,&M,&S,&E); T.initial(N+2); while (M--) { scanf("%d%d%d",&x,&y,&c); T.addline(x,y,c); } printf("%d ",D); printf("%.3lf\n",T.MaxFlow(S,E)*1.0/T.DP(S,E)); } return 0;}
- HDOJ 4240 - Route Redundancy 最大流+DP...阅读理解...
- hdoj 4240 Route Redundancy 【最大流+ SPFA】
- [最大流] hdu 4240 Route Redundancy
- hdu 4240 Route Redundancy(最大流)
- hdu 4240 Route Redundancy(最大流)
- hdu 4240 Route Redundancy 最大流 isap
- HDU 4240 Route Redundancy【最大流】
- HDU 4240 Route Redundancy 一条流最大的路径
- HDU — 4240 Route Redundancy(最大流)
- HDU 4240 --Route Redundancy【最大流dinic && DFS】
- 【 hdoj 4240】 Route Redundancy 【dinic+spfa】
- HDU 4240 Route Redundancy(基础) [最大流]一条流最大的路径
- hdu 4240 Route Redundancy 网络流
- HDU 4240 Route Redundancy 网络流
- HDU 4240 Route Redundancy
- HDU 4240 Route Redundancy
- hdu 4240 Route Redundancy(dinic)
- 【网络流】 HDU4240 Route Redundancy 基础
- .net对html的抓取
- 《一位父亲给梦鸽女士的一封信》全文
- 《火球——UML大战需求分析》(第1章 大话UML)——1.1 UML基础知识扫盲
- 类定义中class和className中间的修饰词的作用有关问题
- linux学习方法的不断感悟
- HDOJ 4240 - Route Redundancy 最大流+DP...阅读理解...
- 关于参数RESUMABLE_TIMEOUT
- 让时间高效
- 深圳成人教育
- 大白菜ZSKAME下载 2013官方地址
- win7下设置局域网能访问本地tomcat服务器
- 《孙子兵法》中的项目管理之道
- 编程之美3.6 编程判断两个链表是否相交
- Mac OS X 10.8 Xcode4.5.1下编译MPlayer OSX Extended