很久以前就见过的。。。最基本的概率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 <DP>

    链接: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. CF715C:Digit Tree

    传送门 一句话怎么说来着 算法+高级数据结构=OI 现在我感觉到的是 我会的算法+我会的高级数据结构=WA 这道题提交了三四十次,从刚看题到完全写好花了好几天..,主要死于看错费马小定理的适用条件. ...

  2. 深入JVM-有关String的内存泄漏

    什么是内存泄漏?所谓内存泄漏,就是由于疏忽或错误造成程序未能释放已经不再使用的内存的情况,他并不是说物理内存消失了,而是指由于不再使用的对象占据了内存不被释放,而导致可用内存不断减小,最终有可能导致内 ...

  3. uC/OS-II应用程序代码

    /*************************************************************************************************** ...

  4. c中三大区的解析

    1.栈,堆和静态存储区是 堆和静态存储区是C语言程序常涉及的三个基本内语言程序常涉及的三个基本内存区2.栈区主要用于函数调用的使用3.堆区主要是用于内存的动态申请和归还4.静态存储区用于保存全局变量和 ...

  5. rdesktop in linux

    rdesktop -f -a 16 -u administrator -p passwrod feelamcheung 192.168.0.2:8080

  6. 【浅谈html5 响应式布局之自动适应屏幕宽度】

    允许网页宽度自动调整 “自适应网页设计”到底是怎么做到的?其实并不难. 首先,在网页代码的头部,加入一行viewport元标签. <meta name=”viewport” content=”w ...

  7. windows7-PowerDesigner 15.1 的安装图解

    下载 PowerDesigner 15.1 的安装文件和破解文件 破解文件下载地址:http://pan.baidu.com/share/link?shareid=177873&uk=3626 ...

  8. 第2章 jQuery的选择器

    选择器是jQuery的根基 一. 认识 1.CSS常用的选择器 标签选择器,后代选择器,Id选择器,通配符选择器,类选择器,群组选择器——主流浏览器全部支持 伪类选择器,子选择器,临近选择器等等——不 ...

  9. ecshop show_message

    格式lib_main.php show_message(内容, array(返回列表,继续编辑), array(连接地址一,链接地址二, 'info',false); true:自动跳转 输出: fu ...

  10. C#中事件的使用

    C#中事件的使用  http://www.cnblogs.com/wayfarer/archive/2004/04/20/6712.html 用一个例子来说明事件的使用. 创建一个简单的类,名为Fil ...