【网络流】poj 1273 Drainage Ditches
来源:互联网 发布:js 原生ajax 编辑:程序博客网 时间:2024/06/17 13:08
第一次写网络流的算法,巨水的题目......利用残留网络不断的寻找增广路径就行了。
#include<iostream>#include<queue>using namespace std;bool augment(); //capacity of pipeint capacity[205][205];//previous pipeint record[1005];int n;bool checked[205];queue<int> q;int main(){int pipeNumber,maximum,minimum;int x,y,cap,tmpPre,tmpNext;while(cin>>pipeNumber>>n){for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){capacity[i][j]=0;//node[i][j].capacity=0;//node[i][j].pre=-1;record[i]=-1;}for(int i=0;i<pipeNumber;i++){cin>>x>>y>>cap;//if(cap>capacity[x][y])capacity[x][y]+=cap;}maximum=0;while(augment()==true){tmpPre=record[n];tmpNext=n;minimum=999999;while(tmpPre!=-1){if(capacity[tmpPre][tmpNext]<minimum)minimum=capacity[tmpPre][tmpNext];tmpNext=tmpPre;tmpPre=record[tmpPre];}tmpPre=record[n];tmpNext=n;while(tmpPre!=-1){//更新残留网络 capacity[tmpPre][tmpNext]-=minimum;capacity[tmpNext][tmpPre]+=minimum;tmpNext=tmpPre;tmpPre=record[tmpPre];}maximum+=minimum;}cout<<maximum<<endl;}return 0;}bool augment(){bool havePath;for(int i=1;i<=n;i++)checked[i]=false;while(q.empty()==false)q.pop();checked[1]=true;q.push(1);havePath=false;//广搜寻找增广路径 while(q.empty()==false){int tmp=q.front();//找到增广路径则退出循环 if(tmp==n){havePath=true;break;}q.pop();for(int i=1;i<=n;i++){if(checked[i]==false&&capacity[tmp][i]>0){checked[i]=true;q.push(i);record[i]=tmp;}}}return havePath;}
- poj 1273 Drainage Ditches 网络最大流
- poj 1273 Drainage Ditches--网络流
- 【网络流】poj 1273 Drainage Ditches
- 网络流poj(1273)Drainage Ditches
- POJ 1273 Drainage Ditches 【网络流】
- POJ 1273 Drainage Ditches 网络流模版
- POJ 1273 Drainage Ditches (网络最大流)
- POJ 1273 - Drainage Ditches (网络流)
- POJ 1273 Drainage Ditches 网络流基础
- 【网络流】 POJ 1273 Drainage Ditches
- 网络流模板 POJ 1273 Drainage Ditches
- poj 1273 Drainage Ditches 经典网络流
- POJ 1273 Drainage Ditches 网络流算法 .
- POJ 1273 Drainage Ditches (网络流)
- 【POJ】1273 Drainage Ditches 网络最大流
- POJ 1273 Drainage Ditches 网络流 ISAP
- POJ 1273 Drainage Ditches(网络流——最大流)
- poj 1273 Drainage Ditches(网络流最大流)
- MyEclipse提示键配置、提示快捷键、提示背景色、关键字颜色、代码显示、编...
- Java线程(九):Condition-线程通信更高效的方式
- Python2.6+Django1.4+Mysql5.5+eclipse的环境搭建
- 8086 汇编语言 走迷宫之 左手法则
- Python入门教程
- 【网络流】poj 1273 Drainage Ditches
- 删除stl list 类对象
- imagemagic实现gif图片的缩略图
- DHTML是dynamic HTML短语的缩写,即动态HTML
- NSXmlParser使用文件路径的问题
- 编写优美的GTest测试案例
- HBase 在淘宝的应用和优化
- 连连看算法
- IIS 6 注册表优化