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. VMWARE虚拟机无法访问的三种方法分析

    bridged(桥接模式). NAT(网络地址转换模式) host-only(主机模式). 理论认识: 1.bridged(桥接模式) 在这个地方模式.虚拟机等同于网络内的一台物理主机,可对手动设置I ...

  2. role &#39;PLUSTRACE&#39; does not exist

    I have created a new user named watson and granted the related priviledges as following: SQL> cre ...

  3. freemarker定义自己的标签错误(八)

    1.错误叙述性说明 freemarker.core.ParseException: Token manager error: freemarker.core.TokenMgrError: Unknow ...

  4. CSDN markdown 编辑 第五章 UML

    这里大概只能产生两种类型的图: 序列图 框图 序列图 ```sequence A->B: 一句话证明你非常寂寞. Note right of B: thinking B->B: count ...

  5. VS2008让自己掌控的定义编译项目后,自己主动添加到工具箱

    在VS2008中,假设在项目里写了一个用户控件.编译后这个控件是不会自己主动出现到工具箱的.按例如以下设置就能够解决问题 工具=>选项=>Windows窗口设计器=>常规=>A ...

  6. (大数据工程师学习路径)第一步 Linux 基础入门----环境变量与文件查找

    环境变量与文件查找 本节介绍环境变量的作用与用法,及几种搜索文件的方法.学会这些技巧高效地使用 Linux. 一.环境变量 1.变量 要解释环境变量,得先明白变量是什么,准确的说应该是 Shell 变 ...

  7. Linux(CentOS)系统下安装好apache(httpd)服务后,其他电脑无法访问的原因

    原文:Linux(CentOS)系统下安装好apache(httpd)服务后,其他电脑无法访问的原因 今天试了下在虚拟机上利用CentOS系统的yum命令安装好了httpd(apache2.4.6), ...

  8. XML DTD详解(转)

    前情提要与本文内容介绍 前面的两篇XML相关博文: 第一篇是介绍格式正规的XML: 格式正规的XML:语法 属性 实体 处理指令 样式单 CDATA节 第二篇介绍DTD,引入有效的XML的概念(符合语 ...

  9. android浏览器开发小技巧集锦(转)

    本人和朋友们做了一段时间浏览器,将一些小技巧分享出来,先写一部分,慢慢写,同时也为我们的浏览器打打广告 我们的浏览器将要上线,名叫沙发浏览 1.网页内的右键菜单 public boolean onLo ...

  10. SQL Server编程系列(1):SMO介绍

    原文:SQL Server编程系列(1):SMO介绍 续篇:SQL Server编程系列(2):SMO常用对象的有关操作 最近在项目中用到了有关SQL Server管理任务方面的编程实现,有了一些自己 ...