Educational Codeforces Round 13 E. Another Sith Tournament 状压dp
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的更多相关文章
- Educational Codeforces Round 13 E. Another Sith Tournament 概率dp+状压
题目链接: 题目 E. Another Sith Tournament time limit per test2.5 seconds memory limit per test256 megabyte ...
- CF1103D Codeforces Round #534 (Div. 1) Professional layer 状压 DP
题目传送门 https://codeforces.com/contest/1103/problem/D 题解 失去信仰的低水平选手的看题解的心路历程. 一开始看题目以为是选出一些数,每个数可以除掉一个 ...
- Codeforces 678E Another Sith Tournament 状压DP
题意: 有\(n(n \leq 18)\)个人打擂台赛,编号从\(1\)到\(n\),主角是\(1\)号. 一开始主角先选一个擂主,和一个打擂的人. 两个人之中胜的人留下来当擂主等主角决定下一个人打擂 ...
- Codeforces Round #585 (Div. 2) E. Marbles(状压dp)
题意:给你一个长度为n的序列 问你需要多少次两两交换 可以让相同的数字在一个区间段 思路:我们可以预处理一个数组cnt[i][j]表示把i放到j前面需要交换多少次 然后二进制枚举后 每次选择一个为1的 ...
- 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 ...
- Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP
Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10061 ...
- [多校联考2019(Round 5 T1)] [ATCoder3912]Xor Tree(状压dp)
[多校联考2019(Round 5)] [ATCoder3912]Xor Tree(状压dp) 题面 给出一棵n个点的树,每条边有边权v,每次操作选中两个点,将这两个点之间的路径上的边权全部异或某个值 ...
- Codeforces 1225G - To Make 1(bitset+状压 dp+找性质)
Codeforces 题目传送门 & 洛谷题目传送门 还是做题做太少了啊--碰到这种题一点感觉都没有-- 首先我们来证明一件事情,那就是存在一种合并方式 \(\Leftrightarrow\) ...
- Educational Codeforces Round 13
http://codeforces.com/contest/678 A:水题 #include<bits/stdc++.h> #define fi first #define se sec ...
随机推荐
- shell脚本实现分日志级别输出
shell脚本如何优雅的记录日志信息,下面让我们一步一步,让shell脚本的日志也变得高端起来,实现如下功能 ①设定日志级别,实现可以输出不同级别的日志信息,方便调试 ②日志格式类似为:[日志级别] ...
- linux shell语言编程规范安全篇之通用原则【转】
shell语言编程规范安全篇是针对bash语言编程中的数据校验.加密与解密.脚本执行.目录&文件操作等方面,描述可能导致安全漏洞或风险的常见编码错误.该规范基于业界最佳实践,并总结了公司内部的 ...
- ETL利器Kettle实战应用解析系列三
本系列文章主要索引如下: 一.ETL利器Kettle实战应用解析系列一[Kettle使用介绍] 二.ETL利器Kettle实战应用解析系列二 [应用场景和实战DEMO下载] 三.ETL利器Kettle ...
- MongoDB安全:所有操作(Privilege Actions)
本文展示了两张思维导图,分别是MongoDB 3.6.4.0的所有权限操作,未做深入研究,仅仅是列出来. 3.6总共9类105个操作,4.0版本比3.6多了两类操作,同时增加了3个操作,共11类108 ...
- CSS3实现文字折纸效果
CSS3实现文字折纸效果 效果图: 代码如下,复制即可使用: <!DOCTYPE html> <html> <head> <title></tit ...
- epoll对poll(select)的改进
select的几大缺点: 每次调用select,都需要把fd集合从用户态拷贝到内核态,这个开销在fd很多时会很大: 每次调用select,内核需要遍历传递进来的所有fd(判断检测文件是否可用).有 ...
- php和mysql两种不同方式的分割字符串和类型转换
一.sql语句1.分割字符串方法:substring_index(字符串,'分隔符',正数从左数起几位/负数从右数起几位); 例如:subtring_index('aa_bb_cc_dd','_',1 ...
- css 让背景图片不停旋转
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- JS验证表单中TEXT文本框中是否含有非法字符
<form id="form" action="" method="post"> <input type="hi ...
- FileBeat读取特征目录及特征文件,为不同的path生成不同的Kafka Topic
进入日志收集及监控报警这个领域,感觉一切都要从新学习. 现在周五,这周有两天用来踩坑了. 作些记录. 第一个遇到的问题,就是不同的应用组件,在k8s里,会生成不同的日志,如何采集到这些不同的日志呢? ...