博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3308(最小割+对数处理)
阅读量:7063 次
发布时间:2019-06-28

本文共 3614 字,大约阅读时间需要 12 分钟。

这题有一个非常坑人的地方,  product 这个单词在这题里是 “相乘"  的意思.   

然后就是最小割模型的建立,s=0,t=m+n+1 然后从s到1-m建权为Ci一条边,从 m+1 - m+n 建立到t的权值为Ri的边。 然后每个伞兵的坐标(x,y) 建立x->y权为无穷大的边.   

这题关键的一点叫我们求所有费用的乘积最小,可以知道的是用最小割模型求出的是所有费用的和, 如果想处理乘法运算看似很难办, 但是有一种很灵巧的方法:

将每条边的权值先取对数(log是以e为底,log10是以10为底),然后其中网络流中的操作都为+-,对于对数就相当于乘除, 可知如果最后求出去对数后的权值和最大,然后exp(e的平方)一下就可以得到最大的总乘积. 

以后遇到乘法难以处理时,想想用对数转化为+- 的运算是否可以解决.

 

Paratroopers
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 5432   Accepted: 1617

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 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

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 #define N 110 8 #define M 5*N*N 9 #define INF 0x3ffffff 10 11 struct node 12 { 13 int to,next; 14 double w; 15 }edge[M]; 16 17 int cnt,pre[N]; 18 int s,t; 19 int nn; 20 int n,m; 21 int lv[N],gap[N]; 22 23 void add_edge(int u,int v,double w) 24 { 25 edge[cnt].to=v; 26 edge[cnt].w=w; 27 edge[cnt].next=pre[u]; 28 pre[u]=cnt++; 29 } 30 31 double sdfs(int k,double w) 32 { 33 if(k==t) return w; 34 double f=0; 35 int mi=nn-1; 36 for(int p=pre[k];p!=-1;p=edge[p].next) 37 { 38 int v=edge[p].to; 39 if(edge[p].w!=0) 40 { 41 if(lv[k]==lv[v]+1) 42 { 43 double tmp=sdfs(v,min(w-f,edge[p].w)); 44 f+=tmp; 45 edge[p].w-=tmp; 46 edge[p^1].w+=tmp; 47 if(f==w||lv[s]==nn) return f; 48 } 49 if(lv[v]

 

转载地址:http://rznll.baihongyu.com/

你可能感兴趣的文章
[书目20130316]jQuery UI开发指南
查看>>
Sql Server系列:开发存储过程
查看>>
Find INTCOL#=1001 in col_usage$?
查看>>
AutoCAD 命令统计魔幻球的实现过程--(3)
查看>>
dp学习笔记1
查看>>
newlisp debugger
查看>>
Java进阶02 异常处理
查看>>
java 动态代理
查看>>
微信5.0绑定银行卡教程
查看>>
数字转换为壹仟贰佰叁拾肆的Java方法
查看>>
引发网页布局灾难的7个大错误
查看>>
一个表单对应多个提交按钮,每个提交按钮对应不同的行为
查看>>
tomcat集群时统计session与在线人数
查看>>
Android程序完全退出
查看>>
【Linux】目录权限与文件权限
查看>>
如何将阿拉伯数字每三位一逗号分隔,如:15000000转化为15,000,000
查看>>
select的使用(一)
查看>>
[leetcode]Search a 2D Matrix @ Python
查看>>
java.io.BufferedOutputStream 源码分析
查看>>
Load resources from classpath in Java--reference
查看>>