# uva 10746 - Crime Wave - The Sequel（最小费用流+精度）！！没提交对，不知道是不是精度的事， 大神求助

0

```  1 #include<cstdlib>
2 #include<iostream>
3 #include<cstdio>
4 #include<cmath>
5 #include<cstring>
6 #include <algorithm>
7 #include<queue>
8 #include<set>
9 #define LL long long
10 #define inf 0x7fffffff
11 #define E 1e-7
12 #define M 100
13 #define N 105
14 using namespace std;
15
16
17
18
19 int n,m;
20 double cost[N][N],d[N];
21 int cap[N][N];
22 int p[N];
23 bool inq[N];
24 int s,t;
25 int num;
26
27
28 double getflow(int s,int t)
29 {
30   queue<int> q;
31   double c=0;
32   int f=0;
33   for(;;)
34     {
35       for(int i=1;i<=t;i++)
36       d[i]=inf;
37       memset(inq,0,sizeof(inq));
38       d[s]=0.0;
39       q.push(s);
40       while(!q.empty())
41         {
42           int u=q.front();
43           q.pop();
44           inq[u]=0;
45           for(int i=1; i<=num; i++)
46             if(cap[u][i]&&d[i]-d[u]-cost[u][i]>-E)
47               {
48                 d[i]=d[u]+cost[u][i];
49                 p[i]=u;
50                 if(!inq[i])
51                   {
52                     q.push(i);
53                     inq[i]=1;
54                   }
55               }
56         }
57
58
59       int a=inf;
60       for(int i=t; i!=s; i=p[i])
61         {
62           a=min(a,cap[p[i]][i]);
63         }
64       for(int i=t; i!=s; i=p[i])
65         {
66           cap[p[i]][i]-=a;
67           cap[i][p[i]]+=a;
68         }
69       f+=a;
70       c+=d[t]*(double)a;
71       if(f==n)
72       break;
73     }
74   return c;
75 }
76 int main()
77 {
78 #ifndef ONLINE_JUDGE
79   freopen("ex.in","r",stdin);
80 #endif
81   while(scanf("%d%d",&n,&m))
82     {
83       if(!n&&!m)
84         break;
85         memset(cap,0,sizeof(cap));
86         memset(cost,0,sizeof(cost));
87         for(int i=1;i<=n;i++)
88         for(int j=1;j<=m;j++)
89         {
90             scanf("%lf",&cost[i][j+n]);
91             cost[j+n][i]=-cost[i][j+n];
92             cap[i][j+n]=1;
93         }
94         for(int i=1;i<=n;i++)
95         cap[0][i]=1;
96         num=m+n+1;
97         for(int i=1;i<=m;i++)
98         cap[i+n][num]=1;
99         s=0;t=num;
100         double ans=getflow(s,t);
101 //        cout<<"ans="<<ans<<endl;
102         printf("%.2lf\n",ans/n);
103
104
105     }
106   return 0;
107 }```
baoff | 初学一级 | 园豆：100

您需要登录以后才能回答，未注册用户请先注册