Description

Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, …, 2n. In each round of the tournament, all teams still in the tournament are placed in a list in order of increasing index. Then, the first team in the list plays the second team, the third team plays the fourth team, etc. The winners of these matches advance to the next round, and the losers are eliminated. After n rounds, only one team remains undefeated; this team is declared the winner.

Given a matrix P = [pij] such that pij is the probability that team i will beat team j in a match determine which team is most likely to win the tournament.

Input

The input test file will contain multiple test cases. Each test case will begin with a single line containing n (1 ≤ n ≤ 7). The next 2n lines each contain 2n values; here, the jth value on the ith line represents pij. The matrix P will satisfy the constraints that pij = 1.0 − pji for all i ≠ j, and pii = 0.0 for all i. The end-of-file is denoted by a single line containing the number −1. Note that each of the matrix entries in this problem is given as a floating-point value. To avoid precision problems, make sure that you use either the double data type instead of float.

Output

The output file should contain a single line for each test case indicating the number of the team most likely to win. To prevent floating-point precision issues, it is guaranteed that the difference in win probability for the top two teams will be at least 0.01.

题目大意

给你$2^n$个球队,必须相邻的球队才可以比赛,在告诉你i球队战胜j球队的概率,问最后哪支球队赢得概率最大。

思路

设$f_{i,j}$表示第$i$次比赛队伍$j$获胜的概率,枚举与$j$比赛的$k$,可得$f_{i,j} = \sum_{k=1}^{2^n}f_{i-1,j}*f_{i-1,k}*p_{j,k}*[$ $\text{j与k相邻} ]$

判断相邻先<<(i-)再用异或(^)运算判断一下即可

/************************************************
*Author : lrj124
*Created Time : 2018.09.30.19:13
*Mail : 1584634848@qq.com
*Problem : poj3071
************************************************/
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn = (1<<7) + 10;
double p[maxn][maxn],f[maxn][maxn];
int n;
int main() {
while (cin >> n) {
if (n == -1) break;
memset(f,0,sizeof(f));
for (int i = 1;i <= (1<<n);i++) {
f[0][i] = 1;
for (int j = 1;j <= (1<<n);j++) scanf("%lf",&p[i][j]);
}
for (int i = 1;i <= (1<<n);i++)
for (int j = 1;j <= (1<<n);j++)
for (int k = 1;k <= (1<<n);k++)
if ((((j-1)>>(i-1))^1) == ((k-1)>>(i-1)))
f[i][j] += f[i-1][j]*f[i-1][k]*p[j][k];
double Max = 0;
int ans;
for (int i = 1;i <= (1<<n);i++)
if (f[n][i] > Max) {
Max = f[n][i];
ans = i;
}
printf("%d\n",ans);
}
return 0;
}

【POJ3071】Football - 状态压缩+期望 DP的更多相关文章

  1. hdu 4649 Professor Tian 反状态压缩+概率DP

    思路:反状态压缩——把数据转换成20位的01来进行运算 因为只有20位,而且&,|,^都不会进位,那么一位一位地看,每一位不是0就是1,这样求出每一位是1的概率,再乘以该位的十进制数,累加,就 ...

  2. [HDU 4336] Card Collector (状态压缩概率dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...

  3. HDU 4739 Zhuge Liang's Mines (状态压缩+背包DP)

    题意 给定平面直角坐标系内的N(N <= 20)个点,每四个点构成一个正方形可以消去,问最多可以消去几个点. 思路 比赛的时候暴力dfs+O(n^4)枚举写过了--无意间看到有题解用状压DP(这 ...

  4. ACM学习历程—HDU1584 蜘蛛牌(动态规划 && 状态压缩 || 区间DP)

    Description 蜘蛛牌是windows xp操作系统自带的一款纸牌游戏,游戏规则是这样的:只能将牌拖到比她大一的牌上面(A最小,K最大),如果拖动的牌上有按顺序排好的牌时,那么这些牌也跟着一起 ...

  5. 洛谷 P2051 [AHOI2009]中国象棋 状态压缩思想DP

    P2051 [AHOI2009]中国象棋 题意: 给定一个n*m的空棋盘,问合法放置任意多个炮有多少种情况.合法放置的意思是棋子炮不会相互打到. 思路: 这道题我们可以发现因为炮是隔一个棋子可以打出去 ...

  6. 【Luogu】P2258子矩阵(状态压缩,DP)

    233今天蒟蒻我连文化课都没听光想着这个了 然后我调了一下午终于过了!!! 一看数据范围似乎是状压,然而216等于65536.开一个65536*65536的二维数组似乎不太现实. 所以Rqy在四月还是 ...

  7. [HNOI2012]集合选数(构造,状态压缩,DP)

    神仙题. 莫名其妙的就试一试把所有数放进一个类似矩阵的东西里面. 首先把 \(1\) 放到左上角,然后在每个数的右边放它的 \(3\) 倍(大于 \(n\) 就不用放了),下面放它的 \(2\) 倍( ...

  8. 过河(状态压缩,dp)

    描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数轴上 ...

  9. ZOJ 3502 Contest <状态压缩 概率 DP>

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3502 #include <iostream> #incl ...

随机推荐

  1. maven项目打包到本地库 两种方式

    方式一 1.项目根路径下 maven clean package 或者 maven package ,根据是否需要跳过代码中的测试代码 加上 -DskipTests 2.mvn install:ins ...

  2. Mybatis(六)逆向工程generator

    逆向工程概述: MyBatis的一个主要的特点就是需要程序员自己编写sql,那么如果表太多的话,难免会很麻烦,所以mybatis官方提供了一个逆向工程,可以针对单表自动生成mybatis执行所需要的代 ...

  3. Android仿支付宝高顶部功能条伸缩动画

    参考:https://blog.csdn.net/aqi00/article/details/72621176

  4. 注册中心Eureka、Zookeeper、Consul的异同点

    先上结论: 基于CAP理论介绍: C:Consistency (强一致性)A:Available (可用性)P:Partition tolerance (分区容错性) 最多只能同时较好的满足两个 CA ...

  5. jquery判断radio是否选中

    微交易-实体系统 微交易-虚拟系统   <div class="system"> <div class="systemt"> <l ...

  6. CSV文件指定页脚

    https://www.cnblogs.com/zhangxinqi/p/9231801.html 2020-06-15

  7. gc 模块常用函数

    """ 1.gc.set_debug(flags) 设置gc的debug日志,一般设置为gc.DEBUG_LEAK 2.gc.collect([generation]) ...

  8. 字典内置函数&方法

    字典内置函数&方法 Python字典包含了以下内置函数:高佣联盟 www.cgewang.com 序号 函数及描述 1 cmp(dict1, dict2)比较两个字典元素. 2 len(dic ...

  9. PDOStatement::columnCount

    PDOStatement::columnCount — 返回结果集中的列数.(PHP 5 >= 5.1.0, PECL pdo >= 0.2.0) 说明 语法 int PDOStateme ...

  10. SpringClould进行Devtools热部署

    当我们在使用SpringCloud搭建项目的时候,会有多个项目,每次修改东西的时候,都需要重新启动项目,这样的操作就比较繁琐. 为了提高工作的效率,避免每次频繁的重启项目,在子类pom文件中,我们可以 ...