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. poj 3348--Cows(凸包求面积)

    链接:http://poj.org/problem?id=3348 Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions:  ...

  2. 4.mybatis属性和表的列名不相同时的处理方法

    /** * 属性和表的列名不相同时的处理方法 * 1.sql中给列重新命名: * select tid id, tname name from teacher t where tid=#{id} * ...

  3. chainOfResponsibility责任链模式

    责任链(Chain of Responsibility)模式 : 责任链模式是对象的行为模式.使多个对象都有机会处理请求,从而避免请求的发送者和接受者直接的耦合关系.将这些处理对象连成一条链,沿着这条 ...

  4. python_way ,day11 线程,怎么写一个多线程?,队列,生产者消费者模型,线程锁,缓存(memcache,redis)

    python11 1.多线程原理 2.怎么写一个多线程? 3.队列 4.生产者消费者模型 5.线程锁 6.缓存 memcache redis 多线程原理 def f1(arg) print(arg) ...

  5. style不同取值对应的日期、时间格式

    from : http://www.cnblogs.com/Gavinzhao/archive/2009/11/10/1599690.html sql server2000中使用convert来取得d ...

  6. [转]产品需求文档(PRD)的写作

    产品需求对产品研发而言非常重要,写不好需求,后面的一切工作流程与活动都会受到影响.转载一篇文章,关于产品需求文档写作方面的,如下: 本文摘自(一个挺棒的医学方面专家):http://www.cnblo ...

  7. Android学习参考2

    一名自学成才的Android开发者怒答! 1. Google做开发前完全是小白,真心不知道有Google这东西,只晓得百 度,遇到问题直接百度,不是黑百度,百度在娱乐八卦方面确实靠谱,但是技术方面查出 ...

  8. iOS - Swift Subscript 下标脚本

    1.Subscript 下标脚本允许你通过在实例后面的方括号中传入一个或者多个的索引值来对实例进行访问和赋值.语法类似于实例方法和计算型属性的混合.与定义实例方法类似,定义下标脚本使用 subscri ...

  9. iOS - UISegmentedControl

    前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UISegmentedControl : UIControl <NSCoding> @available ...

  10. hdu 1081(最大子矩阵和)

    题目很简单,就是个最大子矩阵和的裸题,看来算法课本的分析后也差不多会做了.利用最大子段和的O(n)算法,对矩阵的行(或列)进行 i和j的枚举,对于第 i到j行,把同一列的元素进行压缩,得到一整行的一维 ...