POJ 3308 Paratroopers 最小点权(二分图)
来源:互联网 发布:埃及夏朝 知乎 编辑:程序博客网 时间:2024/06/04 18:24
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 × 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 n positive 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
14 4 52.0 7.0 5.0 2.01.5 2.0 2.0 8.01 12 23 34 41 4
Sample Output
16.0000
Source
#include<stdio.h>#include<math.h>#include<string.h>#define N 3007#define inf 0x3f3f3fint head[N],num,ans,start,end,gap[N],dis[N];struct edge{int st,ed,next;double flow;}e[N*200];void addedge(int x,int y,double w){e[num].st=x;e[num].ed=y;e[num].flow=w;e[num].next=head[x];head[x]=num++;e[num].st=y;e[num].ed=x;e[num].flow=0;e[num].next=head[y];head[y]=num++;}double dfs(int u,double minflow){if(u==end)return minflow;int i,v;double f,flow=0.0;for(i=head[u];i!=-1;i=e[i].next){v=e[i].ed;if(e[i].flow>0){if(dis[v]+1==dis[u]){f=dfs(v,e[i].flow>minflow-flow?minflow-flow:e[i].flow);flow+=f;e[i].flow-=f;e[i^1].flow+=f;if(minflow-flow<=1e-8)return flow;if(dis[start]>=ans)return flow;}}}if(--gap[dis[u]]==0)dis[start]=ans;dis[u]++;gap[dis[u]]++;return flow;}double spfa(){double maxflow=0.0;memset(gap,0,sizeof(gap));memset(dis,0,sizeof(dis));gap[0]=ans;while(dis[start]<ans)maxflow+=dfs(start,inf);return maxflow;}int main(){int i,n,m,k,t;scanf("%d",&t);while(t--){scanf("%d%d%d",&n,&m,&k);memset(head,-1,sizeof(head));num=0;start=0;end=n+m+1;ans=end+1;double anss,val;for(i=1;i<=n;i++){scanf("%lf",&val);addedge(start,i,log(val));}for(i=1;i<=m;i++){scanf("%lf",&val);addedge(i+n,end,log(val));}int a,b;for(int i=1;i<=k;i++){scanf("%d%d",&a,&b);addedge(a,b+n,inf);}anss=spfa();printf("%.4lf\n",exp(anss));}return 0;}
- POJ 3308 Paratroopers 最小点权(二分图)
- POJ 3308 Paratroopers 二分图最小点权覆盖
- POJ 3308 Paratroopers (二分图最小点权覆盖 -> 最小割 -> 最大流)
- pku 3308 Paratroopers(带权二分图最小点覆盖)
- poj 3308 Paratroopers最小点权覆盖
- POJ 3308 Paratroopers (最小点权覆盖Dinic)
- POJ 3308--Paratroopers【 最小点权覆盖 && 最小割】
- POJ 3308 Paratroopers 最小点权覆盖Dinic
- poj_3308 Paratroopers(二分图最小点权覆盖集+dinic+化乘为加)
- poj 3308 Paratroopers(最小割)
- POJ 3308 Paratroopers(最小割+Dinic)
- POJ 3308 Paratroopers (最小割)
- 【POJ】3308 Paratroopers 化乘为加——最小点权覆盖
- POJ 3308 Paratroopers //最小割
- 【最小割】POJ-3308 Paratroopers
- (最小割)poj 3308 Paratroopers
- poj3308 Paratroopers 二分图的最小割
- POJ 3308 二分图最小点权覆盖 最大流
- cleartool常用命令
- 子类编写构造器报错 Implicit super constructor Cigerate() is undefined
- struts2 struts.xml中的methods方法
- libsvm 核函数 交叉验证 参数优化
- C++复制构造函数详解
- POJ 3308 Paratroopers 最小点权(二分图)
- iPhone开发工具篇-charles proxy的使用
- 单片机最小系统
- String格式
- 操作系统之设备管理笔记
- 微信公众平台PHP开发
- Win7 开机后3分钟内硬盘等狂闪解决办法
- iframe取值备忘
- openssl移植