题意翻译

有 \(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. Http接口系列:如何提高Http接口用例的数据稳定性

    此文已由作者王婷英授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 为了尽可能多的释放手工测试,提高测试效率,我们都会想到使用自动化测试,如http接口自动化测试.doubbo ...

  2. 解决Entity Framework查询匿名对象后的跨域访问的一种方式

    在Entity Framework中,可以使用lambda表达式进行对数据的查询,而且可以将查询结果直接映射为对象或者对象列表,这极大的提高的开发速度,并且使数据层的数据更加方便处理和传递.但是很多时 ...

  3. redhat防火墙管理

    systemctl status firewalldsystemctl stop firewalldsystemctl start firewalldsystemctl enable firewall ...

  4. Linux命令应用大词典-第23章 进程和服务管理

    23.1 ps:报告当前进程的快照 23.2 top:显示当前正在运行的进程 23.3 pgrep:按名称和其他属性查找进程 23.4 pidof:查找正在运行的进程的进程号 23.5 pstree: ...

  5. 油田 (Oil Deposits UVA - 572)

    题目描述: 原题:https://vjudge.net/problem/UVA-572 题目思路: 1.图的DFS遍历 2.二重循环找到相邻的八个格子 AC代码: #include <iostr ...

  6. MyBatis 注解配置及动态SQL

      一.注解配置 目前MyBatis支持注解配置,用注解方式来替代映射文件,但是注解配置还是有点不完善,在开发中使用比较少,大部分的企业还是在用映射文件来进行配置.不完善的地方体现在于当数据表中的字段 ...

  7. Linux内核设计笔记11——定时器

    定时器与时间管理笔记 内核中的时间 时钟中断:内核中的系统定时器以某种频率触发中断,该频率可以通过编程预定. 节拍率HZ:时钟中断的频率称为节拍率. 节拍:相邻两次中断的时间间隔称为节拍,1/节拍率. ...

  8. c#和.net区别

    .net 包含两大部分:.net framework类库和公共语言运行库(CLR) .net framework类库,就是微软工程师写好的各种功能类,例如math类. 公共语言运行库:1.与操作系统进 ...

  9. 针对XX系统的可用性和易用性构想

    可用性是与系统故障有关的一个质量属性,是指系统正常运行的时间的比例,一般通过两次故障之间的时间长度或在系统崩溃情况下能恢复正常运行的速度来衡量,同时此概念涉及一个公式的计算,就是系统正常运行时间的百分 ...

  10. Ubuntu16.0.4 安装mysql

    1. sudo apt-get install mysql-server 2. sudo apt-get install mysql-client 3.  sudo apt-get install l ...