Football
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3145   Accepted: 1591

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, thejth 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
概率dp。
题意 : 足球淘汰赛。一共同拥有n轮,共同拥有2^n支队伍參赛,所以总共进行n轮比赛就可以决出冠军。设dp[i][j]为第i轮比赛中j队胜出的概率。则dp[i][j]=dp[i-1][j]*dp[i-1][k]*p[j][k].k为在本轮j的对手。
然后以下的问题是怎样求出k。能够列出在2进制状态下的比赛过程。然后能够发现规律:j>>i-1^1==k>>i-1;
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
#define ll long long
double dp[8][130],p[130][130];
int main()
{
int n;
while(scanf("%d",&n)!=EOF&&n!=-1)
{
int num=1<<n;
memset(dp,0,sizeof(dp));
for(int i=0;i<num;i++)
{
for(int j=0;j<num;j++)
scanf("%lf",&p[i][j]);
dp[0][i]=1;
}
for(int i=1;i<=n;i++)
for(int j=0;j<num;j++)
for(int k=0;k<num;k++)
{
if((j>>(i-1)^1)==(k>>i-1))
dp[i][j]+=dp[i-1][j]*dp[i-1][k]*p[j][k];
}
int ans;double Max=-1;
for(int i=0;i<num;i++)
{
if(dp[n][i]>Max)
{
ans=i+1;
Max=dp[n][i];
}
}
printf("%d\n",ans);
}
return 0;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

POJ 3071-Football(可能性dp)的更多相关文章

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

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

  2. POJ 3071 Football(概率DP)

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

  3. poj 3071 Football(概率dp)

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

  4. poj 3071 Football <DP>

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

  5. POJ 3071 Football:概率dp

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

  6. POJ 3071 Football 【概率DP】

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

  7. POJ 3071 Football (概率DP)

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

  8. POJ 3071 Football

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

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

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

随机推荐

  1. H.265/HEVC Codec 编解码 (MP4 和 TS)

    1. H.265/HEVC 播放器 1) VLC media player 2.1.3 (眼下不支持H.265 TS播放) 2)ffmpeg中的ffplay (如:ffplay  hevc.ts) 3 ...

  2. 云梯vpn

    刚和大饼合买了一个云梯的vpn 表示可以把俺的优惠连接放出来了 貌似必须是新注册用户才能够享用优惠 http://protizi.com/?r=5e3fecd7eae558ec 把云梯推荐给朋友们 让 ...

  3. 几个cd快速提示

    cd是project师每天都会用到的命令. 今天就来分享几条和cd有关的小技巧 cd 假设你用cd ~来进入当前用户的home文件夹的话,那么能够试试直接敲cd. 相同效果,少敲两下键盘. cd - ...

  4. lsblk请参阅块设备

    lsblk可以查看分区和挂载的磁盘使用情况 lsblk全部的參数 -a, --all            显示全部设备  -b, --bytes          以bytes方式显示设备大小  - ...

  5. extjs_03_grid(添加数据)

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  6. Razor和HtmlHelper的使用意义

    Razor和HtmlHelper的使用意义 写这篇文档的目的是为了给初学MVC的同伴们介绍在MVC的View中的两个新概念,能有利于我们更快,更好的开发项目.一个是视图引擎,一个是HtmlHlper. ...

  7. 5、VS2010+ASP.NET MVC4+EF4+JqueryEasyUI+Oracle该项目的开发——使用datagrid做报表

    来点需要:我使用的数据库访问EF框架,但是,因为使用一个动态表来的统计报告中.单独是每天产生基于数据表,它是很难使用EF加盟前.所以我包装在两组数据库存取层的框内,一个是EF,一种是传统的ADO.NE ...

  8. CSDN博文“待定”如何避免检测规则分析“待定”

    这些天一直很郁闷.鲍文本人一直"待定", 当然,这是非常不舒服的自己.那么今晚最终成为一个非成功出版"待定"文章,这CSDN于大家的反映而放弃了.没想到我后面又 ...

  9. Cocos2d-x v3.0 正式版 如何创建一个项目,TestCpp执行

    欢迎增加 Cocos2d-x 交流群: 193411763 转载请注明原文出处:http://blog.csdn.net/u012945598/article/details/24456579 首先到 ...

  10. React实践

    React实践(一)   该实践取自官方教程:https://github.com/reactjs/react-tutorial 主要是自实现的过程以及一些心得体会 该实践是实现一个评论框. 一个展示 ...