# POJ 3308 Paratroopers 最小点权覆盖Dinic

F - Paratroopers
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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 × 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 ith row (resp. column) of the grid yard is ri (resp. ci ) 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 ≤ m ≤ 50 , 1 ≤ n ≤ 50 and 1 ≤ l ≤ 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 ith number is ri and then, a line with npositive real numbers greater or equal to 1.0 comes where the ith number is ci. 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

ACcode：

#pragma warning(disable:4786)//使命名长度不受限制
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rds(x) scanf("%s",x)
#define rdc(x) scanf("%c",&x)
#define ll long long int
#define maxn 100005
#define mod 1000000007
#define INF 1e8 //int 最大值
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define MT(x,i) memset(x,i,sizeof(x))
#define PI  acos(-1.0)
#define E  exp(1)
#define esp 0.00000001
using namespace std;
struct Edge{
int to,next;
double w;
}e[maxn];
void addEdge(int u,int v,double w){
}
bool makelevel(){
double w;
MT(level,-1);
int que[maxn];
int front=0,rear=0,u;
level[rear++]=0;
while(front!=rear){
u=que[front++];
int v=e[k].to;
w=e[k].w;
if(w>esp&&level[v]<0){
level[v]=level[u]+1;
que[rear++]=v;
}
}
}
return level[n+m+1]>=0;
}
double dfs(int now ,double maxf,int t){
if(now==t)return maxf;
double ret=0,s;
int v=e[k].to;
double w=e[k].w;
if(w>esp&&level[v]==level[now]+1&&(s=dfs(v,min(maxf,w),t))){
e[k].w-=s;
e[k^1].w+=s;
return s;
}
}
return 0;
}
double dinic(int s,int t){
double ans=0,ss;
while(makelevel()){
ss=dfs(s,INF,t);
if(ss>esp)
ans+=ss;
else break;
}
return ans;
}
int main(){
rd(loop);
while(loop--){
double val;
int u,v;
tot=0;
rd2(n,m);rd(num);
FOR(i,1,n){
scanf("%lf",&val);
}
FOR(i,1,m){
scanf("%lf",&val);
}
FOR(i,1,num){
rd2(u,v);
}
printf("%0.4lf\n",exp(dinic(0,n+m+1)));
}
return 0;
}
/*
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
*/


• 本文已收录于以下专栏：

## POJ 3308 Paratroopers （最小点权覆盖Dinic）

• Tsaid
• 2011-10-23 22:59
• 831

## poj 3308 Paratroopers 二分图最小点权覆盖集+ 最小割+邻接表

Description It is year 2500 A.D. and there is a terrible war between the forces of the Earth and ...

## poj 3308 Paratroopers最小点权覆盖

//poj 3308 //sep9 #include #include #include using namespace std; const int MAXN=128; const int M...

## POJ 3308 Paratroopers （二分图最小点权覆盖 -> 最小割 -> 最大流）

POJ 3308 Paratroopers 链接：http://poj.org/problem?id=3308 题意：有一个N*M的方阵，有L个伞兵降落在方阵上。现在要将所有的伞兵都消灭掉...

## POJ3308-Paratroopers 【Dinic算法求最大流】

• 2011-09-17 14:19
• 13KB
• 下载

## poj 2125 Destroying The Graph 最小点权覆盖

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)