# POJ 3308 Paratroopers 题解【网络流】【最小点权覆盖集】

## Description

It is year 2500 A.D. and there is a terrible war between the forces of the Earth and the Mars. Recently, the commanders of the Earth are informed by their spies that the invaders of Mars want to land some paratroopers in the $m\times n$ grid yard of one their main weapon factories in order to destroy it. In addition, the spies informed them the row and column of the places in the yard in which each paratrooper will land. Since the paratroopers are very strong and well-organized, even one of them, if survived, can complete the mission and destroy the whole factory. As a result, the defense force of the Earth must kill all of them simultaneously after their landing.

In order to accomplish this task, the defense force wants to utilize some of their most hi-tech laser guns. They can install a gun on a row (resp. column) and by firing this gun all paratroopers landed in this row (resp. column) will die. The cost of installing a gun in the $i$th row (resp. column) of the grid yard is $r_i$ (resp. $c_i$ ) and the total cost of constructing a system firing all guns simultaneously is equal to the product of their costs. Now, your team as a high rank defense group must select the guns that can kill all paratroopers and yield minimum total cost of constructing the firing system.

## Input

Input begins with a number $T$ showing the number of test cases and then, $T$ test cases follow. Each test case begins with a line containing three integers $1\le m\le 50 , 1\le n \le 50$ and $1\le l\le 500$ showing the number of rows and columns of the yard and the number of paratroopers respectively. After that, a line with $m$ positive real numbers greater or equal to $1.0$ comes where the $i$th number is $r_i$ and then, a line with $n$ positive real numbers greater or equal to $1.0$ comes where the $i$th number is $c_i$. Finally, $l$ lines come each containing the row and column of a paratrooper.

## Output

For each test case, your program must output the minimum total cost of constructing the firing system rounded to four digits after the fraction point.

## Sample Input

1
4 4 5
2.0 7.0 5.0 2.0
1.5 2.0 2.0 8.0
1 1
2 2
3 3
4 4
1 4


## Sample Output

16.0000


## 题解：

### tips

• 在poj上交G++double要用%f，交C++时用\$lf

• 这个题由于取了对数，所以最大值不会很大。最大流中的inf设置为1e2即可，此时eps可以设为1e-8。（inf更大就会WA

## Code：

#include<cmath>
#include<cstdio>
#include<cstring>
#define eps 1e-8
double Min(double x,double y)
{
return x<y?x:y;
}
struct edge
{
int n,nxt;
double v;
edge(int n,int nxt,double v)
{
this->n=n;
this->nxt=nxt;
this->v=v;
}
edge(){}
}e;
{
}
int d,q;
bool bfs()
{
int l=0,r=0;
memset(d,0,sizeof(d));
d=1;
q[++r]=123;
while(l<r)
{
int x=q[++l];
if(e[i^1].v>eps&&!d[e[i].n])
{
d[e[i].n]=d[x]+1;
q[++r]=e[i].n;
}
}
return d>0;
}
double dinic(int x,double in)
{
if(x==123)
return in;
double flow=in;
if(e[i].v>eps&&d[e[i].n]==d[x]-1)
{
double tmp=dinic(e[i].n,Min(flow,e[i].v));
if(tmp<eps)
d[e[i].n]=0;
e[i].v-=tmp;
e[i^1].v+=tmp;
flow-=tmp;
}
return in-flow;
}
int main()
{
#ifdef wjyyy
freopen("data.in","r",stdin);
freopen("ans.out","w",stdout);
#endif
int T,n,m,t,u,v;
double w;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&t);
ecnt=-1;
for(int i=1;i<=n;++i)
{
scanf("%lf",&w);
}
for(int i=1;i<=m;++i)
{
scanf("%lf",&w);
}
for(int i=1;i<=t;++i)
{
scanf("%d%d",&u,&v);
}
double ans=0;
while(bfs())
{
double tmp;
do
{
tmp=dinic(0,1e2);
ans+=tmp;
}while(tmp>eps);
}
printf("%.4lf\n",exp(ans));
}
return 0;
}


### 说点什么 Subscribe

/* */