POJ3308_Paratroopers(最大流最小割)
来源:互联网 发布:java软件license破解 编辑:程序博客网 时间:2024/05/21 20:26
原题地址:点击打开链接
#include<stdio.h>#include<queue>#include<math.h>#include<string.h>using namespace std;#define MAX 99999double min(double x,double y){return x<y?x:y;}double map[110][110];int pos[110];int cheng[110]; bool bfs(int s,int t){int i;memset(cheng,-1,sizeof(cheng));queue<int>que;que.push(s);cheng[s]=0;while(!que.empty()){int u=que.front();que.pop();for(i=0;i<=t;i++){if(map[u][i]>0&&cheng[i]==-1){cheng[i]=cheng[u]+1;que.push(i);}}}if(cheng[t]!=-1)return true;return false;}double dfs(int u,int t,double f){if(u==t)return f;for(int &i=pos[u];i<=t;i++){if(map[u][i]>0 && cheng[u]==cheng[i]-1){double d=dfs(i,t,min(f,map[u][i]));if(d>0){map[u][i]-=d;map[i][u]+=d;return d;}}}return 0;}double max_flow(int s,int t){double res=0;while(bfs(s,t)){memset(pos,0,sizeof(pos));while(true){double d=dfs(s,t,MAX);if(d<=0)break;res+=d;}}return exp(res);}int main(){int i,j,c,m,n,l,s,t,u,v;double cost;scanf("%d",&c);while(c--){scanf("%d%d%d",&m,&n,&l);s=0;t=m+n+1;memset(map,0,sizeof(map));for(i=1;i<=m;i++){scanf("%lf",&cost);map[s][i]=log(cost);}for(i=1;i<=n;i++){scanf("%lf",&cost);map[m+i][t]=log(cost);}for(i=1;i<=l;i++){scanf("%d%d",&u,&v);map[u][m+v]=MAX;}double res=max_flow(s,t);printf("%0.4lf\n",res);}return 0;}
0 0
- POJ3308_Paratroopers(最大流最小割)
- 最大流/最小割
- 最大流最小割
- 最大流最小割
- 最大流最小割
- 最大流最小割
- 最大流最小割定理
- 最大流-最小割简介
- 最大流最小割定理
- poj3308 最大流最小割
- 最小割转最大流
- 最大流和最小割
- 最小割最大流记录
- hdu2435最大流最小割
- 最大流最小割定理
- 最大流最小割---FordFulkerson
- 最大流最小割算法
- 最大流最小割定理
- 【原创】USB接口颜色的那些事儿
- 用yum环境在线安装svn mvn
- C++之vector
- 分页 分页 分页
- C++之vector
- POJ3308_Paratroopers(最大流最小割)
- 杭电oj 1009
- 如何获取文件的大小?
- angularjs
- 【转】对象!什么叫合适!
- 有点可爱的抽象类
- iOS 动画解析 支付宝支付动画 下
- C++之list
- memcached//分布式数据缓存