hdu3549最大流
来源:互联网 发布:叶修官方手办淘宝 编辑:程序博客网 时间:2024/06/13 16:20
这应该是最裸的最大流题了吧,刚开始学最大流,拿来练练手。从源点到汇点的最大流,EK算法实现如下,不再多说:http://acm.hdu.edu.cn/showproblem.php?pid=3549
#include<iostream>#include<cstring>#include<cmath>#include<cstdio>using namespace std;#define INS 0xfffffff#define MAX 105int map[MAX][MAX],f[MAX];int r[MAX];bool vis[MAX];int m,n;bool bfs(){ int start,end,size,begin = 0; start = end = 0; size = 100; memset(vis,false,sizeof(vis)); r[start] = 1; int k = 1; while(start <= end){ vis[ r[start] ] = true; for(int i = 1;i <= n;++i){ if(!vis[i] && map[ r[start] ][i] > 0){ end = (end+1)%size; f[i] = r[start]; r[end] = i; if(i == n) return true; } } start = (start+1)%size; } return false;}int E_K(){ int d = INS,i,res = 0; memset(f,-1,sizeof(f)); f[1] = 0; while(bfs()){ i = n; d = INS; while(f[i] != 0){ d = min(d,map[ f[i] ][i]); i = f[i]; } i = n; res += d; while(f[i] != 0){ map[ f[i] ][i] -=d; map[i][ f[i] ] +=d; i = f[i]; } memset(f,-1,sizeof(f)); f[1] = 0; } return res;}int main(){ int t; scanf("%d",&t); for(int k = 1;k <= t;++k){ scanf("%d%d",&n,&m); int b,e,v; memset(map,0,sizeof(map)); for(int i = 0;i < m;++i){ scanf("%d%d%d",&b,&e,&v); map[b][e] += v; } printf("Case %d: %d\n",k,E_K()); } return 0;}
- hdu3549最大流
- 最大流HDU3549
- hdu3549 (dinic求最大流)
- HDU3549 Flow Problem 【最大流】
- hdu3549 最大流模板题
- HDU3549 Flow Problem(最大流)
- hdu3549 Flow Problem【最大流】
- HDU3549(最大流算法的Dinic算法)
- hdu3549及最大流dinic模板
- hdu3549及最大流ISAP模板
- hdu3549 Flow Problem 最大流模板 isap
- hdu3549炒鸡果的最大流[dinic]
- hdu3549--Flow Problem(初识最大流)
- HDU3549 Flow Problem【最大流】【Edmond-Karp】
- hdu3549 Flow Problem(最大流)
- hdu3549(又是最大流模板题)
- hdu3549 Flow Problem--EK算法 & 最大流
- hdu3549-Flow Problem(最大流&EK)
- 《那些年啊,那些事——一个程序员的奋斗史》——63
- H-Jtag V1.0 烧写NOR Flash
- 找规律。。&&http://acm.hdu.edu.cn/showproblem.php?pid=1097
- H-Jtag V1.0 烧写NOR Flash
- 关于年均增长率
- hdu3549最大流
- java 字符串 处理
- Windows7部署Android开发环境傻瓜式教程(Eclipse+ADT)
- Oracle中job的使用详解.txt
- 2012年开发者应做的11件事
- telechips 8803 串口乱码问题
- cvCreateStructuringElementEx
- 关于使用微软的Script Encoder 加密JavaScript代码出错的研究!
- 如何在VC++6.0中修改主窗口风格