Football
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2667   Accepted: 1361

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.

Sample Input

  1. 2
  2. 0.0 0.1 0.2 0.3
  3. 0.9 0.0 0.4 0.5
  4. 0.8 0.6 0.0 0.6
  5. 0.7 0.5 0.4 0.0
  6. -1

Sample Output

  1. 2
  1. /*分析:如果dp[i][j]表示进行第i次比赛j赢得概率
  2. 则主要在于计算第i次比赛可能与j相邻的队伍t而且本次是与t比赛
  3. 然后dp[i][j]+=dp[i-1][j]*dp[i-1][t]*p[j][t]
  4. 对于t怎样算?
  5. 如果队伍id:
  6. 0 1 2 3 4 5 6 7
  7. 对于第一轮比赛相对上一轮比赛:
  8. 0属于第一个赢家,1属于第二个赢家,2属于第三个赢家,3属于第四个赢家...
  9. 第一次比赛后:
  10. 0/1 2/3 4/5 6/7
  11. 对于第二轮比赛相对上一轮比赛:
  12. 0/1属于第一个赢家,2/3属于第二个赢家...
  13. 能够发现规律都是:
  14. 第奇数个赢家和前一个赢家比赛
  15. 第偶数个赢家和后一个赢家比赛
  16. 也不难发现规律。对于第j个队伍在第i次比赛
  17. 属于第j/(2^(i-1))个赢家//从0開始
  18. */
  19. #include <iostream>
  20. #include <cstdio>
  21. #include <cstdlib>
  22. #include <cstring>
  23. #include <string>
  24. #include <queue>
  25. #include <algorithm>
  26. #include <map>
  27. #include <cmath>
  28. #include <iomanip>
  29. #define INF 99999999
  30. typedef long long LL;
  31. using namespace std;
  32.  
  33. const int MAX=(1<<7)+10;
  34. const int N=10+10;
  35. int n;
  36. double p[MAX][MAX],dp[N][MAX];//dp[i][j]表示第i回合j胜利的概率
  37.  
  38. int main(){
  39. while(~scanf("%d",&n),n != -1){
  40. int bit=1<<n;
  41. for(int i=0;i<bit;++i){
  42. for(int j=0;j<bit;++j)scanf("%lf",&p[i][j]);
  43. }
  44. memset(dp,0,sizeof dp);
  45. for(int i=0;i<bit;++i)dp[0][i]=1;
  46. for(int i=1;i<=n;++i){
  47. for(int j=0;j<bit;++j){
  48. int t=j>>(i-1);//j经历i-1次属于第t个赢家
  49. if(t&1){//j为奇数赢家,本次将与第j-1个赢家比赛
  50. for(int k=t*(1<<(i-1))-1;k>=(t-1)*(1<<(i-1));--k){
  51. dp[i][j]+=dp[i-1][j]*dp[i-1][k]*p[j][k];
  52. }
  53. }else{//j为偶数赢家,本次将与第j+1个赢家比赛
  54. for(int k=(t+1)*(1<<(i-1));k<(t+2)*(1<<(i-1));++k){
  55. dp[i][j]+=dp[i-1][j]*dp[i-1][k]*p[j][k];
  56. }
  57. }
  58. }
  59. }
  60. int id=0;
  61. for(int i=0;i<bit;++i){
  62. if(dp[n][i]>dp[n][id])id=i;
  63. }
  64. printf("%d\n",id+1);
  65. }
  66. return 0;
  67. }

poj3071之概率DP的更多相关文章

  1. POJ3071:Football(概率DP)

    Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, …, 2 ...

  2. [poj3071]football概率dp

    题意:n支队伍两两进行比赛,求最有可能获得冠军的队伍. 解题关键:概率dp,转移方程:$dp[i][j] +  = dp[i][j]*dp[i][k]*p[j][k]$表示第$i$回合$j$获胜的概率 ...

  3. POJ3071 Football 概率DP 简单

    http://poj.org/problem?id=3071 题意:有2^n个队伍,给出每两个队伍之间的胜率,进行每轮淘汰数为队伍数/2的淘汰赛(每次比赛都是相邻两个队伍进行),问哪只队伍成为冠军概率 ...

  4. 概率dp专辑

    求概率 uva11021 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  5. 动态规划之经典数学期望和概率DP

    起因:在一场训练赛上.有这么一题没做出来. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6829 题目大意:有三个人,他们分别有\(X,Y,Z\)块钱 ...

  6. Codeforces 28C [概率DP]

    /* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...

  7. HDU 4405 Aeroplane chess (概率DP)

    题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i  这个位置到达 n ...

  8. POJ 2096 Collecting Bugs (概率DP)

    题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...

  9. POJ 2151 Check the difficulty of problems (概率DP)

    题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...

随机推荐

  1. (转)c++ typedef 函数指针详细说明

    转自:http://blog.csdn.net/future200x/article/details/5350134 一个函数在编译时被分配一个入口地址,将这个入口地址称为函数的指针,可以用一个指针变 ...

  2. 0x05 排序

    说是排序结果就是各种奇技淫巧 中位数被坑多了久病成医,例题一题搞笑一题糖果传递(昨晚精神那么好效率还那么差) #include<cstdio> #include<iostream&g ...

  3. javascript中的闭包以及闭包应用

    闭包简单理解就是能够读取其他函数内部变量的函数,而在javascript中只有内部函数可以读取函数的内部变量,所以我们学习javascript时可以这样理解,函数A中嵌套了一个函数B,然后我们用函数B ...

  4. HTML5学习笔记(四):关于表格

    在一个实例中碰到表格,总结下,先上代码,例: <table border="1"> <thead> <th>表头</th> < ...

  5. Redis学习笔记(七) 基本命令:Set操作

    原文链接:http://doc.redisfans.com/set/index.html 虽然set和list很相似但还是有一些差别的,如set中的顺序没有先后之分,所以不像list一样可以在首尾增删 ...

  6. ROS-单目摄像头标定

    前言:由于摄像图内部与外部的原因,生成的图像往往会发生畸变,为了避免数据源造成的误差,需要针对摄像头的参数进行标定. ros官方提供了camera_calibration软件包进行摄像头标定. 一.安 ...

  7. BZOJ 4184 线段树+高斯消元

    思路: 线段树表示的是时间 每回最多log个段 区间覆盖 一直到叶子 的线性基 xor 一下 就是答案 一开始没有思路 看了这篇题解 豁然开朗 http://www.cnblogs.com/joyou ...

  8. BZOJ4819: [Sdoi2017]新生舞会(01分数规划)

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1029  Solved: 528[Submit][Status][Discuss] Descripti ...

  9. Thingworx SDK开发自定义Widget

    Thingworx自带的图表数量有限,样式也很有限,在echarts上看到了这样一个非常简单的图表,下面将做一个简单的静态引入示范 首先创建Thingworx项目 然后右键ui新建widget 自动生 ...

  10. css——导航栏

    导航栏一般用无序列表制作 但出来的导航栏有黑点,还有一些边距 去除黑点我们可以用:list-style-type: none;/*去掉ul前面的点*/ 因为有些标签之间会有默认的边距,所以可以先将边踞 ...