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. 04_IOC容器装配Bean(xml方式)

    IOC容器装配Bean(xml方式) 1.Spring 提供配置Bean三种实例化方式 1)使用类构造器实例化(默认无参数) <bean id="bean1" class=& ...

  2. 发布《Linux工具快速教程》

    发布<Linux工具快速教程> 阶段性的完成了这本书开源书籍,发布出来给有需要的朋友,同时也欢迎更多的朋友加入进来,完善这本书: 本书Github地址:https://github.com ...

  3. ManualResetEvent & AutoResetEvent

      参考资料: 1. https://msdn.microsoft.com/en-us/library/system.threading.manualresetevent.aspx 2. https: ...

  4. FLASH CC 2015 CANVAS 导出图片出现缩放问题

    最近有项目 没时间更新教程 刚才出现一个问题 就是导出动画后,发现有图片无故被缩放(与软件内的设置不一样) 经过排查 发现动画师 直接将位图 进行了缩放, 导出后出现问题 把文图转换为影片剪辑后,做缩 ...

  5. 查看perl及其模块

    Perl本身自带了很丰富的文档,如果把它们都打印出来,恐怕要耗费大量纸墨.我们试图清点过,但数到2000页左右的时候就数不清了(不用担心,我们用虚拟打印机计算页面数量,这样不会对树木造成威胁,挺环保的 ...

  6. ubuntu12.04 gdb安装使用

    参考文档:http://blog.csdn.net/haoel/article/details/2879 http://www.programlife.net/gdb-manual.html [新手笔 ...

  7. 工具配置(eclipse/plsql)

      PLSQL 附常用配置: PrefAutomaticStatistics=True SelectedStatNames= AutoSelectSQL=True ShowSQLWindowGutte ...

  8. iOS - UIImagePickerController

    前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIImagePickerController : UINavigationController <NSCod ...

  9. Python变量类型

    Python变量类型 变量是存储在内存中的值,因此在创建变量时会在内存中开辟一个空间. 基于变量的数据类型,解释器会分配指定的内存,并决定什么数据可以被存储在内存中. 因此变量可以指定不同的数据类型, ...

  10. count-the-repetitions

    https://leetcode.com/problems/count-the-repetitions/ 下面是我的方法,结果对的,超时了... package com.company; class ...