题意翻译

有 \(n\) 个人去执行 \(n\) 个任务,每个人执行每个任务有不同的成功率,每个人只能执行一个任务,求所有任务都执行的总的成功率。

输入第一行,一个整数 \(n\) ( \(1\leq n\leq 20\) ),表示人数兼任务数。接下来 \(n\) 行每行 \(n\) 个数,第 \(i\) 行第 \(j\) 个数表示第 \(i\) 个人去执行第 \(j\) 个任务的成功率(这是一个百分数,在 \(0\) 到 \(100\) 间)。

输出最大的总成功率(这应也是一个百分数)

题目描述

Everyone knows of the secret agent double-oh-seven, the popular Bond (James Bond). A lesser known fact is that he actually did not perform most of his missions by himself; they were instead done by his cousins, Jimmy Bonds. Bond (James Bond) has grown weary of having to distribute assign missions to Jimmy Bonds every time he gets new missions so he has asked you to help him out. Every month Bond (James Bond) receives a list of missions. Using his detailed intelligence from past missions, for every mission and for every Jimmy Bond he calculates the probability of that particular mission being successfully completed by that particular Jimmy Bond. Your program should process that data and find the arrangement that will result in the greatest probability that all missions are completed successfully. Note: the probability of all missions being completed successfully is equal to the product of the probabilities of the single missions being completed successfully.

输入输出格式

输入格式:

The first line will contain an integer N, the number of Jimmy Bonds and missions (1 ≤ N ≤ 20). The following N lines will contain N integers between 0 and 100, inclusive. The j-th integer on the ith line is the probability that Jimmy Bond i would successfully complete mission j, given as a percentage.

输出格式:

Output the maximum probability of Jimmy Bonds successfully completing all the missions, as a percentage.

输入输出样例

输入样例#1:

2

100 100

50 50

输出样例#1:

50.000000

输入样例#2:

2

0 50

50 0

输出样例#2:

25.00000

输入样例#3:

3

25 60 100

13 0 50

12 70 90

输出样例#3:

9.10000

说明

Clarification of the third example: If Jimmy bond 1 is assigned the 3rd mission, Jimmy Bond 2 the 1st mission and Jimmy Bond 3 the 2nd mission the probability is: 1.0 0.13 0.7 = 0.091 = 9.1%. All other arrangements give a smaller probability of success. Note: Outputs within ±0.000001 of the official solution will be accepted.

题解

考虑建出二分图

发现这题很想带权二分图匹配是吧,但是由于答案是算乘法,所以不能直接匹配

思考乘法的转化 \(a=x^{log_xa}\) ,\(a*b=x^{log_xa}x^{log_xb}=x^{log_xa+log_xb}\)

于是就很好地把乘法变成了加法

于是就可以上费用流跑带权二分图匹配了

注意,0没有对数,所以要特判

#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
const int MAXN=20+5,intinf=0x3f3f3f3f;
const db doubleinf=1000000000.00;
int n,e=1,to[MAXN*MAXN*2],nex[MAXN*MAXN*2],beg[MAXN<<1],cap[MAXN*MAXN*2],p[MAXN<<1],cur[MAXN<<1],vis[MAXN<<1],clk,s,t;
db was[MAXN*MAXN*2],ans,level[MAXN<<1];
std::queue<int> q;
template<typename T> inline void read(T &x)
{
T data=0,w=1;
char ch=0;
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline void insert(int x,int y,int z,db k)
{
to[++e]=y;
nex[e]=beg[x];
beg[x]=e;
cap[e]=z;
was[e]=k;
to[++e]=x;
nex[e]=beg[y];
beg[y]=e;
cap[e]=0;
was[e]=-k;
}
inline bool bfs()
{
for(register int i=1;i<=n+n+2;++i)level[i]=doubleinf;
level[s]=0;
p[s]=1;
q.push(s);
while(!q.empty())
{
int x=q.front();
q.pop();
p[x]=0;
for(register int i=beg[x];i;i=nex[i])
if(cap[i]&&level[to[i]]>level[x]+was[i])
{
level[to[i]]=level[x]+was[i];
if(!p[to[i]])
{
p[to[i]]=1;
q.push(to[i]);
}
}
}
return level[t]!=doubleinf;
}
inline int dfs(int x,int maxflow)
{
if(x==t||!maxflow)return maxflow;
vis[x]=clk;
int res=0,f;
for(register int &i=cur[x];i;i=nex[i])
if((vis[x]^vis[to[i]])&&cap[i]&&level[to[i]]==level[x]+was[i])
{
f=dfs(to[i],min(maxflow,cap[i]));
maxflow-=f;
res+=f;
cap[i]-=f;
cap[i^1]+=f;
ans+=(db)f*was[i];
if(!maxflow)break;
}
vis[x]=0;
return res;
}
inline int MCMF()
{
int res=0;
while(bfs())clk++,memcpy(cur,beg,sizeof(cur)),res+=dfs(s,intinf);
ans-=(db)res*100;
return res;
}
int main()
{
read(n);
for(register int i=1;i<=n;++i)
for(register int j=1;j<=n;++j)
{
int x;read(x);
if(x)insert(i,n+j,1,-(db)log((db)x/100)/(db)log(10)+100);
}
s=n+n+1,t=s+1;
for(register int i=1;i<=n;++i)insert(s,i,1,0),insert(i+n,t,1,0);
if(MCMF()!=n)puts("0.0000000");
else printf("%.7f\n",pow(10,-ans)*100);
return 0;
}

【刷题】洛谷 P4329 [COCI2006-2007#1] Bond的更多相关文章

  1. 洛谷 P2046 BZOJ 2007 海拔(NOI2010)

    题目描述 YT市是一个规划良好的城市,城市被东西向和南北向的主干道划分为n×n个区域.简单起见,可以将YT市看作 一个正方形,每一个区域也可看作一个正方形.从而,YT城市中包括(n+1)×(n+1)个 ...

  2. 2018.10.30 一题 洛谷4660/bzoj1168 [BalticOI 2008]手套——思路!问题转化与抽象!+单调栈

    题目:https://www.luogu.org/problemnew/show/P4660 https://www.lydsy.com/JudgeOnline/problem.php?id=1168 ...

  3. AC日记——大爷的字符串题 洛谷 P3709

    大爷的字符串题 思路: 莫队,需开O2,不开50: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 20000 ...

  4. Mychael原创题 洛谷T23923 Mychaelの水题 【题解】

    原题链接 题目大意: 有来自三个地区的人各a,b,c位,他们排成了一排.请问有多少种不同类型的排法,使得相邻的人都来自不同的地区 \(a,b,c<=200\) 答案取模 题解 弱弱的标程解法 设 ...

  5. 最短路径Dijkstra算法模板题---洛谷P3371 【模板】单源最短路径(弱化版)

    题目背景 本题测试数据为随机数据,在考试中可能会出现构造数据让SPFA不通过,如有需要请移步 P4779. 题目描述 如题,给出一个有向图,请输出从某一点出发到所有点的最短路径长度. 输入格式 第一行 ...

  6. [网络流24题] 洛谷P2761 软件补丁问题

    题意:某公司发现其研制的一个软件中有 n个错误,随即为该软件发放了一批共 m 个补丁程序.对于每一个补丁 i ,都有 2 个与之相应的错误集合 B1(i)和 B2(i),使得仅当软件包含 B1(i)中 ...

  7. 高精度加法——经典题 洛谷p1601

    题目背景 无 题目描述 高精度加法,x相当于a+b problem,[b][color=red]不用考虑负数[/color][/b] 输入输出格式 输入格式: 分两行输入a,b<=10^500 ...

  8. [洛谷P4329][COCI2006-2007#1] Bond

    题目大意:有$n$个人有$n$个任务,每个人执行每个任务有不同的成功率,每个人只能执行一个任务,求所有任务都执行的总的成功率. 题解:可以跑最大费用最大流,把成功率取个$log$,最后$exp$回去就 ...

  9. 洛谷 P1131 [ ZJOI 2007 ] 时态同步 —— 树形DP

    题目:https://www.luogu.org/problemnew/show/P1131 记录 x 子树内同步的时间 f[x],同步所需代价 g[x]: 直接转移即可,让该儿子子树与其它儿子同步, ...

随机推荐

  1. Mysql忘记密码处理办法

    找回密码的步骤如下: 1.停止mysql服务器 sudo /opt/lampp/lampp stopmysql 2.使用`--skip-grant-tables' 参数来启动 mysqld sudo ...

  2. 学习Drupal一个容易被忽视的问题

    刚刚修复了一个问题,一个非常小的问题,但我花了2-3小时才查明原因并修复. 总结下来我忽视了一个非常常见的问题或者没有养成一个好的习惯. 问题现象是:论坛发帖,只有editor以上权限的人可以发帖,也 ...

  3. Appium的一点一滴:Android KEYCODE键值

    转自:http://blog.csdn.net/crisschan/article/details/50419963 - 电话键 键名 描述 键值 KEYCODE_CALL 拨号键 5 KEYCODE ...

  4. Fiddler - 拦截手机请求

    1. 在电脑上安装Fillder. 安装好之后的Fiddler 打开是这样的: 2. 浏览器访问http://127.0.0.1:8888/fiddler,下载证书并安装 3. 打开抓取https请求 ...

  5. 韦大仙--简单的monkey测试命令行操作及生成log日志保存

    作中,在将apk交给软件测试人员去测试之前,不免要自己先自测,monkey自测是一个不错的选择! 步骤很简单: 1.测试用的手机与电脑连接好USB ,并且安装好驱动(我一般都是通过豌豆荚自动安装的)! ...

  6. Spring全局变量

    压测spring框架的webservice接口,大并发量下响应值与预期值不一致 经查,开发在类中使用全局变量导致: springmvc核心控制器DispatcherServlet 默认为每个contr ...

  7. 适配iPhoneX、iPhoneXs、iPhoneXs Max、iPhoneXr 屏幕尺寸及安全区域

    此篇文章是对上一篇文章(http://www.ifiero.com/index.php/archives/611)的进一步补充,主要说明如何适配Apple的最新三款手机iPhoneXs.iPhoneX ...

  8. Python常用函数--文档字符串DocStrings

    Python 有一个甚是优美的功能称作python文档字符串(Documentation Strings),在称呼它时通常会使用另一个短一些的名字docstrings.DocStrings 是一款你应 ...

  9. 题解 CF682C 【Alyona and the Tree】

    简单搜索题,我们每找到一组不满足题目给出条件的点和边就将其整个子树删除,然后最终答案加上该子树的大小即可.注意,搜索的时候如果当前的边权和sum已经为负了,应该将其改为0(可以想想为什么) 注:题目翻 ...

  10. ionic ios样式偏移解决方案。

    在css属性内增加: .item-ios [item-end] { //解决ios系统上尾部图标出现重影而增加的格式. margin: 0px -15.3px 0px 0px; margin-bott ...