Football
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3469   Accepted: 1782

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 offloat.

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

2
0.0 0.1 0.2 0.3
0.9 0.0 0.4 0.5
0.8 0.6 0.0 0.6
0.7 0.5 0.4 0.0
-1

Sample Output

2

Hint

In the test case above, teams 1 and 2 and teams 3 and 4 play against each other in the first round; the winners of each match then play to determine the winner of the tournament. The probability that team 2 wins the tournament in this case is:

P(2 wins)  P(2 beats 1)P(3 beats 4)P(2 beats 3) + P(2 beats 1)P(4 beats 3)P(2 beats 4)
p21p34p23 + p21p43p24
= 0.9 · 0.6 · 0.4 + 0.9 · 0.4 · 0.5 = 0.396.

The next most likely team to win is team 3, with a 0.372 probability of winning the tournament.

Source

 
概率dp(简单的求概率)
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define N 130
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
using namespace std;
#define MAXN 2
#define ll double
double p[N][N], win[][N]; int main()
{
int n;
while(~scanf("%d", &n) && n != -)
{
for(int i = ; i <= ( << n); i++)
for(int j = ; j <= ( << n); j++)
scanf("%lf", &p[i][j]);
for(int i = ; i <= ( << n); i++) win[][i] = 1.0; double t;
for(int i = ; i <= n; i++)
for(int j = ; j <= ( << n); j++) {
int k = (j - ) / ( << (i - ));
t = 0.0;
if(k % )
for(int q = (k - ) * ( << (i - )) + ; q <= k * ( << (i - )); q++)
t += win[i - ][j] * win[i - ][q] * p[j][q];
else
for(int q = (k + ) * ( << (i - )) + ; q <= (k + ) * ( << (i - )); q++)
t += win[i - ][j] * win[i - ][q] * p[j][q];
win[i][j] = t;
} double maxn = -1.0;
int winner = ;
for(int i = ; i <= ( << n); i++)
if(win[n][i] > maxn) maxn = win[n][i], winner = i; printf("%d\n", winner); }
return ;
}

Football(POJ3071)的更多相关文章

  1. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  2. poj3071 Football(概率dp)

    poj3071 Football 题意:有2^n支球队比赛,每次和相邻的球队踢,两两淘汰,给定任意两支球队相互踢赢的概率,求最后哪只球队最可能夺冠. 我们可以十分显然(大雾)地列出转移方程(设$f[ ...

  3. 我的MYSQL学习心得(六) 函数

    我的MYSQL学习心得(六) 函数 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类 ...

  4. java面试题及答案(转载)

    JAVA相关基础知识1.面向对象的特征有哪些方面 1.抽象:抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分,暂时 ...

  5. 使用 PHP 过滤器(Filter)进行严格表单验证

    PHP 过滤器(Filter)用于验证和过滤来自非安全来源的数据,比如用户的输入,使用过滤器扩展可以使数据过滤更轻松快捷.要求的 PHP 版本是 PHP 5 >= 5.2.0,PHP 7 和 F ...

  6. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  7. Java面试题大全(四)

    JAVA代码查错 1. abstract class Name { private String name; public abstract boolean isStupidName(String n ...

  8. (转)MySQL联表查询

    资料源于网络   一.内联结.外联结.左联结.右联结的含义及区别在SQL标准中规划的(Join)联结大致分为下面四种:1.内联结:将两个表中存在联结关系的字段符合联结关系的那些记录形成记录集的联结.2 ...

  9. JfreeChart使用(转载)

    http://www.cnblogs.com/xingyun/ http://www.huosen.net/archives/156.html(此篇除了struts2外,还介绍了servlet下Jfr ...

随机推荐

  1. 数据词典与ABAP类型映射

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  2. DOM 表单应用

    1.大小写转换 <script> var a='aaa'; var b='AaA'; var c='BbB'; //alert(c.toLowerCase()); //把含有大写的字母转换 ...

  3. 《转》Ubuntu 12.04常用的快捷键

    Ubuntu 12.04常用的快捷键   超级键操作   1.超级键(Win键)–打开dash.   www.2cto.com   2.长按超级键– 启动Launcher.并快捷键列表.   3.按住 ...

  4. 表单美化-原生javascript和jQuery多选按钮(兼容IE6)

    前些天我们讲了下单选按钮的美化今天来做表单元素多选按钮的美化.我们的想法是:利用多选按钮是否被选中和是否不给选择的特性来为按钮的父元素添加对应的样式,就是说用什么的样式是由按钮的状态来决定. 用到的图 ...

  5. 加载.properties方式

    相对路径时注意:是相对项目(即包下)还是相对当前类(一般都是相对当前项目)(对于非class的资源文件eclipse编译时会直接放到bin目录下) 1.一般是从目录中加载:需要指明路径 2.另外就是通 ...

  6. spring注入简记

    我们知道对象是交给容器来管理的那么 init() destroy():可以在bean配置中设置对象初识化前执行和销毁后执行 int-delay=""表示是否延迟实例化即容器实例时还 ...

  7. V8 引擎的sort算法

    用的是快速排序,有点小问题 function ArraySort(comparefn) { // In-place QuickSort algorithm. // For short (length ...

  8. SQLserver批量删除空表

    今天需要清理一个很大的数据库,里面表有一堆,而且有很多是空表.想着把数据库弄小点,于是想到一次性删掉所有空表. 废话不多说,上代码. 首先,查处所有的空表. select distinct a.nam ...

  9. Monkey学习(1)环境搭建

    环境搭建: Monkey程序由Android系统自带,需要配置J2SE平台的JDK,还需要配置Android平台的SDK. 1)下载和配置JDK 下载与安装JDK过程省略... 配置JDK环境变量,我 ...

  10. 搭建LNMP环境

    下载软件包 百度云地址下载地址:http://pan.baidu.com/s/1eSfWNoY 一共有17个包 [root@localhost lnmp]# ls /usr/local/src/lnm ...