E. Another Sith Tournament

题目连接:

http://www.codeforces.com/contest/678/problem/E

Description

The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each battle in the Sith Tournament ends with a death of one of opponents? The Tournament ends when the only Sith remains alive.

Jedi Ivan accidentally appeared in the list of the participants in the Sith Tournament. However, his skills in the Light Side of the Force are so strong so he can influence the choice of participants either who start the Tournament or who take the loser's place after each battle. Of course, he won't miss his chance to take advantage of it. Help him to calculate the probability of his victory.

Input

The first line contains a single integer n (1 ≤ n ≤ 18) — the number of participants of the Sith Tournament.

Each of the next n lines contains n real numbers, which form a matrix pij (0 ≤ pij ≤ 1). Each its element pij is the probability that the i-th participant defeats the j-th in a duel.

The elements on the main diagonal pii are equal to zero. For all different i, j the equality pij + pji = 1 holds. All probabilities are given with no more than six decimal places.

Jedi Ivan is the number 1 in the list of the participants.

Output

Output a real number — the probability that Jedi Ivan will stay alive after the Tournament. Absolute or relative error of the answer must not exceed 10 - 6.

Sample Input

3
0.0 0.5 0.8
0.5 0.0 0.4
0.2 0.6 0.0

Sample Output

0.680000000000000

Hint

题意

有n个人在决斗,两个决斗,然后胜利者继续决斗

你是0号人物,你可以安排比赛顺序,问你最大的获胜概率是多少

题解:

状压dp

你是最后一个上场的人,这个结论猜一下就好了。

然后倒着做。

dp[i][j]表示你还要干死状态i的人,当前正在打的人是j,然后你获胜的最大概率是多少

然后直接状压dp莽一波就好了。

注意,这个状态是倒着的。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 18;
double p[maxn][maxn],dp[1<<maxn][maxn];
int main()
{int n;scanf("%d",&n);for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>p[i][j];dp[1][0]=1;for(int i=0;i<(1<<n);i++){for(int j=0;j<n;j++)if(i&(1<<j)){for(int k=0;k<n;k++)if(i&(1<<k)&&(k!=j))dp[i][j]=max(dp[i][j],p[j][k]*dp[i^(1<<k)][j]+p[k][j]*dp[i^(1<<j)][k]);}}double ans = 0;for(int i=0;i<n;i++)ans=max(ans,dp[(1<<n)-1][i]);printf("%.12f\n",ans);
}

Educational Codeforces Round 13 E. Another Sith Tournament 状压dp相关推荐

  1. Codeforces Round #585 (Div. 2) E. Marbles 状压dp + 逆序对

    传送门 文章目录 题意: 思路: 题意: 思路: 考虑数列最终的状态一定是相同颜色在一起,所以我们发现他的颜色是有顺序的!显然可以用状压dpdpdp来枚举颜色的顺序,但是又有问题了,你怎么确定当前这个 ...

  2. Codeforces 678E:Another Sith Tournament 状压DP

    odd-even number 题目链接: http://codeforces.com/problemset/problem/678/E 题意: 有n个人打擂台赛,每两个人间都有相对的胜率,主角可以操 ...

  3. Educational Codeforces Round 13

    A. Johny Likes Numbers Johny likes numbers n and k very much. Now Johny wants to find the smallest i ...

  4. Codeforces Beta Round #8 C. Looking for Order 状压dp

    题目链接: http://codeforces.com/problemset/problem/8/C C. Looking for Order time limit per test:4 second ...

  5. [2021-09-02 contest]CF1251C,可达性统计(bitset优化dp),Boomerang Tournament(状压dp),小蓝的好友(mrx)(treap平衡树)

    文章目录 CF1251C Minimize The Integer acwing164:可达性统计 Facebook Hacker Cup 2016 Round 1 Boomerang Tournam ...

  6. Educational Codeforces Round 13 A.Johny Likes Numbers B. The Same Calendar

    传送门 A. Johny Likes Numbers time limit per test0.5 seconds memory limit per test256 megabytes inputst ...

  7. Educational Codeforces Round 103 (Rated for Div. 2) D. Journey dp

    传送门 题意: 给n+1n+1n+1个点,每两个点之间有一个字符L(表示i+1连向i)L(表示i+1连向i)L(表示i+1连向i)或者R(表示i连向i+1)R(表示i连向i+1)R(表示i连向i+1) ...

  8. 【CodeForces - 580D】Kefa and Dishes (状压dp)

    题干: kefa进入了一家餐厅,这家餐厅中有n个菜(0<n≤18),kefa对第i个菜的满意度为ai(0≤ai≤10^9),并且对于这n个菜有k个规则,如果kefa在吃完第xi个菜之后吃了第yi ...

  9. Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)

    Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...

最新文章

  1. Pixhawk原生固件以往代码版本的下载
  2. Objective-C中的@property和@synthesize用法
  3. oracle的除,Oracle数据库如何去除别名 - daiyan0526的个人空间 - 51Testing软件测试网 51Testing软件测试网-软件测试人的精神家园...
  4. matlab——图像细化
  5. Linux 出现Permission denied的解决办法
  6. DataList项模板中的div在后台得到方法
  7. 蓝桥杯 BASIC-1 基础练习 闰年判断
  8. .与localhost与 .\sqlexpress的区别
  9. poi导出使用HSSFWorkbook行数超出
  10. Ubuntun 18.04 NVIDIA显卡驱动安装
  11. PS:换背景天空(简单抠图)
  12. greenplum-cc-web4.0监控安装
  13. 通过源码分析Mybatis运行原理
  14. 综述(三)无人驾驶中感知系统的工作流程及原理
  15. MacOS swift 首页导航栏 不显示标题问题
  16. 一边「盆满钵满」,一边「卸磨杀驴」,这家龙头企业也整骚操作?
  17. html输入表单jsp返回数据中文乱码,JSP/Servlet页面中文显示为乱码的解决方式
  18. 软件项目管理 6.4.类比(自顶向下)估算法
  19. ignore的音标_英语ignore的意思解释|读音发音|相关词语_英语词典_词林在线词典...
  20. DyGLIP:跨摄像头多目标跟踪的动态图模型

热门文章

  1. 计算c53的c语言的程序,C程序设计的常用算法.doc
  2. hadoop 文本统计一个字符的个数_使用hadoop统计多个文本中每个单词数目
  3. 如何线程安全的使用HashMap
  4. 人工智能简史(Rockwell Anyoha )
  5. php服务器队列执行,lnmp php添加队列服务器的配置
  6. input python2.7_python 中的input
  7. vue项目实现记住密码到cookie功能
  8. 用PC端Chrome浏览器进行模拟微信浏览器的开发
  9. Pytorch搭建yolo3目标检测平台
  10. 初学Java Web(3)——第一个Servlet