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. STL源码剖析:仿函数

    仿函数就是函数对象 函数对象: 重载了operator()的类对象 使用起来和普通函数一致,所以称为函数对象或是仿函数 STL中对于仿函数的参数进行了特殊处理,定义了两个特殊类,类里面只有类型定义 一 ...

  2. 回文树(回文自动机)(PAM)

    第一个能看懂的论文:国家集训队2017论文集 这是我第一个自己理解的自动机(AC自动机不懂KMP硬背,SAM看不懂一堆引理定理硬背) 参考文献:2017国家集训队论文集 回文树及其应用 翁文涛 参考博 ...

  3. 无法定位序数242于动态链接库,Anaconda3\Library\bin\mkl_intel_thread

    python.exe-找不到序数:无法定位序数242与动态链接库libiomp5md.dll上.或无法定位程序输入点 mkl_dft_create_descriptor_md于动态链接库 Ancond ...

  4. heredoc

    Heredoc在正规的PHP文档中和技术书籍中一般没有详细讲述.他是一种Perl风格的字符串输出技术.使用heredoc技术可以实现界面与代码的准分离,比如phpwind模板.规则如下:1.”< ...

  5. Java中的锁机制

    1.在Java中锁的分类 其实就是按照锁的特性分类的 公平锁,非公平锁 可重入锁 独享锁,共享锁 互斥锁,读写锁 乐观锁,悲观锁 分段锁 偏向锁,轻量级锁,重量级锁 自旋锁 相关资料:思维导图 使用场 ...

  6. Linux中配置端口转发(反向代理)

    在conf.d目录下建一个文件, 以conf为结尾(如果没有conf.d目录,就自己新建一个) server { listen 80; server_name 127.0.0.1; #这个IP是你服务 ...

  7. 安排上了!PC人脸识别登录,出乎意料的简单

    本文收录在个人博客:www.chengxy-nds.top,技术资源共享. 之前不是做了个开源项目嘛,在做完GitHub登录后,想着再显得有逼格一点,说要再加个人脸识别登录,就我这佛系的开发进度,过了 ...

  8. Python重命名和删除文件

    Python重命名和删除文件: rename(当前的文件名,新文件名): 将当前的文件名修改为新文件名 程序: # os.rename('旧名字',’新名字‘) import os os.rename ...

  9. FPGA内部IP核DDS

    项目当中需要正弦信号与余弦信号,首先想到了DDS芯片,例如AD9833.AD9834.由于还需要用FPGA   做一些数据处理,后来干脆直接用FPGA 内部的DDSIP核,同时根据IP核内部的相位累加 ...

  10. 2020牛客暑期多校训练营 第二场 C Cover the Tree 构造 贪心

    LINK:Cover the Tree 最受挫的是这道题,以为很简单 当时什么都想不清楚. 先胡了一个树的直径乱搞的贪心 一直过不去.后来意识到这类似于最经典长链剖分优化贪心的做法 然后那个是求最大值 ...