很久以前就见过的。。。最基本的概率DP。。。
除法配合位运算可以很容易的判断下一场要和谁比。    from——Dinic算法

                        Football
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2499   Accepted: 1258

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

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

Stanford Local 2006

 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int n,N;
double win[][];
double dp[][]; int main()
{
while(scanf("%d",&n)!=EOF&&n!=-)
{
N=<<n;
for(int i=;i<N;i++) for(int j=;j<N;j++) scanf("%lf",&win[i][j]);
memset(dp,,sizeof(dp));
for(int i=;i<N;i++) dp[i][]=;
for(int k=;k<=n;k++)
{
int B=<<(k-);
for(int i=;i<N;i++)
{
int temp=i/B;
for(int j=;j<N;j++)
{
if((temp^)==(j/B))
dp[i][k]+=dp[i][k-]*dp[j][k-]*win[i][j];
}
}
}
int pos=;
for(int i=;i<N;i++)
{
if(dp[i][n]>dp[pos][n]) pos=i;
}
printf("%d\n",pos+);
} return ;
}

POJ 3071 Football的更多相关文章

  1. poj 3071 Football(概率dp)

    id=3071">http://poj.org/problem? id=3071 大致题意:有2^n个足球队分成n组打比赛.给出一个矩阵a[][],a[i][j]表示i队赢得j队的概率 ...

  2. poj 3071 Football &lt;DP&gt;

    链接:http://poj.org/problem?id=3071 题意: 有 2^n 支足球队,编号 1~2^n,现在给出每支球队打败其他球队的概率,问哪只球队取得冠军的概率最大? 思路: 设dp[ ...

  3. POJ 3071 Football:概率dp

    题目链接:http://poj.org/problem?id=3071 题意: 给定n,有2^n支队伍参加足球赛. 给你所有的p[i][j],表示队伍i打败队伍j的概率. 淘汰赛制.第一轮(1,2)两 ...

  4. POJ 3071 Football 【概率DP】

    Football Football Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3734   Accepted: 1908 ...

  5. poj 3071 Football (概率DP水题)

    G - Football Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  6. poj 3071 Football(线段树+概率)

    Football Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2801   Accepted: 1428 Descript ...

  7. POJ 3071 Football(概率DP)

    题目链接 不1Y都对不住看过那么多年的球.dp[i][j]表示i队进入第j轮的概率,此题用0-1<<n表示非常方便. #include <cstdio> #include &l ...

  8. POJ 3071 Football (概率DP)

    概率dp的典型题.用dp[j][i]表示第j个队第i场赢的概率.那么这场要赢就必须前一场赢了而且这一场战胜了可能的对手.这些都好想,关键是怎么找出当前要算的队伍的所有可能的竞争对手?这个用异或来算,从 ...

  9. 【POJ 3071】 Football(DP)

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

随机推荐

  1. psp个人软件开发

    为开发人员提供一个PSP工具,简化时间记录工作:同时提供数据使用的工具,帮助开发人提高估算能力.  需求分析: 编号 特性 FEAT01 研发经理能够创建项目.指定或修改项目经理.删除尚未分配工作任务 ...

  2. PYTHON第三天

    PYTHON之路 七.基本的if判断 最简单的流程处理: if ...else If简单练习: #!/usr/bin/env  python # -*-coding:utf-8 -*- #if 基本表 ...

  3. Redhat linux 挂载命令mount

    命令格式: mount [-t vfstype] [-o options] device dir 其中: 1.-t vfstype 指定文件系统的类型,通常不必指定.mount 会自动选择正确的类型. ...

  4. H3C远程登陆配置

    1.配置本地用户(默认权限 level 1) [H3C]local-user admin [H3C-luser-admin]password cipher [H3C]super password le ...

  5. Part 9 Sorting data in AngularJS

    To sort the data in Angular 1. Use orderBy filter     {{ orderBy_expression | orderBy : expression : ...

  6. shell中$0,$?,$!等的特殊用法【转载】

    本文转载自:http://blog.sina.com.cn/s/blog_464f6dba0100psy9.html ----------------------------------------- ...

  7. javascript计算啤酒2元一瓶,4个盖换一瓶,2个瓶换一瓶,10元钱最多喝多少瓶

    var n = 0//当前剩下多少瓶加上喝赢了多少瓶 var x = 5//初始多少瓶 var y = 0//除了喝掉的,剩下多少瓶 var z = 0;//总数 var arr = []//定义一个 ...

  8. 【Python】解析Python的缩进规则

    Python中的缩进(Indentation)决定了代码的作用域范围.这一点和传统的c/c++有很大的不同(传统的c/c++使用花括号花括号{}符决定作用域的范围:python使用缩进空格来表示作用域 ...

  9. c/c++ 获取数组长度

    在C/C++中并没有提供直接获取数组长度的函数 c/c++ 获取数组长度其中一种方法是使用sizeof(array) / sizeof(array[0]). 在C语言中习惯上在使用时都把它定义成一个宏 ...

  10. c语言const和c++const

    1.常量 常量是指值不能被改变的量,又叫做字面值 1.1常量分类 1)字符常量:'a', 'A', '*'. 2)字符串常量:"helloworld","ilovechi ...