###### HDU 3395 Special Fish 费用流
//author: CHC
//First Edit Time:	2014-10-11 20:13
//Last Edit Time:	2014-10-11 20:39
//求最大费用，不要求最大流
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <limits>
using namespace std;
typedef long long LL;
const int MAXN=210;
const int MAXM=1e+4;
const int INF= numeric_limits<int>::max();
const LL LL_INF= numeric_limits<LL>::max();
struct Edge
{
int from,to,ci,cost,next;
Edge(){}
Edge(int _from,int _to,int _ci,int _cost,int _next):from(_from),to(_to),ci(_ci),cost(_cost),next(_next){}
}e[MAXM];
int q[MAXM];
int dis[MAXN],pre[MAXN],rec[MAXN],vis[MAXN];
inline void init(){
tot=0;
}
inline void AddEdge1(int u,int v,int ci,int cost){
}
inline bool spfa(int S,int T,LL &cost,LL &flow){
int i,h=0,t=0;
for(i=0;i<=MAXN;i++){
dis[i]=INF;
vis[i]=false;
}
q[h]=S;
dis[S]=0;
vis[S]=true;
while(h<=t){
int u=q[h++];
vis[u]=false;
int v=e[i].to;
if(e[i].ci>0&&dis[v]>dis[u]+e[i].cost){
dis[v]=dis[u]+e[i].cost;
pre[v]=u;
rec[v]=i;
if(!vis[v]){
vis[v]=1;
q[++t]=v;
}
}
}
}
if(dis[T]==INF)return false;
if(dis[T]>=0)return false;
int minn=INF;
for(i=T;i!=S;i=pre[i]){
if(e[rec[i]].ci<minn)
minn=e[rec[i]].ci;
}
for(i=T;i!=S;i=pre[i]){
//cost+=minn*e[rec[i]].cost;
e[rec[i]].ci-=minn;
e[rec[i]^1].ci+=minn;
}
cost+=dis[T]*minn;
flow+=minn;
return true;
}
inline void mincostmaxflow(int S,int T,LL &cost,LL &flow){
while(spfa(S,T,cost,flow));
}
int v[MAXN];
int main()
{
int n;
while(~scanf("%d",&n)){
if(n==0)break;
for(int i=1;i<=n;i++)scanf("%d",&v[i]);
init();
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
char x;
scanf(" %c",&x);
}
}
for(int i=1;i<=n;i++){
}
LL cost=0,flow=0;
mincostmaxflow(0,1,cost,flow);
cost=-cost;
printf("%I64d\n",cost);
}
return 0;
}

#### hdu 3395 Special Fish(费用流//KM匹配)

2013-11-06 21:00:02

#### HDU 3395 Special Fish(费用流)

2014-09-12 17:23:36

#### hdu 3395 Special Fish(费用流)

2014-04-16 20:26:19

#### hdoj 3395 Special Fish 【最大费用流】

2015-08-30 02:05:32

#### HDU 3395 special fish

2011-05-11 20:12:00

#### HDU 3395 Special Fish

2014-08-30 11:49:26

#### hdu 3395 Special Fish

2013-02-21 16:22:16

#### hdu（3395）Special Fish

2013-08-03 22:17:11

#### hdu 3395 Special Fish【最大费用流】

2016-08-22 17:40:33

#### hdu 3395 Special Fish 最大费用流

2015-10-07 19:21:47

## 不良信息举报

HDU 3395 Special Fish 费用流