Football
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2882   Accepted: 1466

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 nrounds, 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 representspij. 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.

Time: 79MS
#include"iostream"
#include"cstdio"
#include"cstring"
using namespace std;
const int ms=;
double p[ms][ms];
double dp[ms][];
int main()
{
int n,i,j;
while(scanf("%d",&n),n!=-)
{
int m=(<<n);
for(i=;i<m;i++)
{
for(j=;j<m;j++)
scanf("%lf",&p[i][j]);
dp[i][]=;
}
int ans;
for(i=;i<n;i++)
{
ans=;
for(j=;j<m;j++)
{
double sum=;
for(int k=(<<i);k<(<<(i+));k++)
{
sum+=dp[k^j][i]*p[j][k^j];
}
dp[j][i+]=dp[j][i]*sum;
if(dp[j][i+]>dp[ans][i+])
ans=j;
}
}
printf("%d\n",ans+);
}
return ;
}

Football的更多相关文章

  1. POJ 3071 Football

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

  2. Football Foundation (FOFO) TOJ 2556

    The football foundation (FOFO) has been researching on soccer; they created a set of sensors to desc ...

  3. 17111 Football team

    时间限制:1000MS  内存限制:65535K 提交次数:0 通过次数:0 题型: 编程题   语言: C++;C Description As every one known, a footbal ...

  4. CodeForces 432B Football Kit

     Football Kit Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Subm ...

  5. Football(POJ3071)

    Football Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3469   Accepted: 1782 Descript ...

  6. 16年大连网络赛 1006 Football Games

    题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?cid=725&pid=1006 Football Games Time ...

  7. 三分--Football Goal(面积最大)

    B - Football Goal Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Su ...

  8. HDU5873:Football Games

    题目链接: Football Games 分析: 先将分数排序,然后 设当前队编号为p,设个指针为p+1,然后p>1,每次p-=2,指针右移一位p==1,指针指向的队-=1p==0,从指针开始到 ...

  9. Codeforces Gym 100425H H - Football Bets 构造

    H - Football BetsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

随机推荐

  1. spoj 839 Optimal Marks(二进制位,最小割)

    [题目链接] http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17875 [题意] 给定一个图,图的权定义为边的两端点相抑或值的 ...

  2. linux查看端口信息以及关闭进程

     lsof -i:6633 查看端口6633的使用情况 kill  (+PID数值),结束进程

  3. 为Android游戏接入第三方登录功能

    1. “游戏客户端”调用“SDK客户端”的登录功能向“SDK服务端”进行身份认证 2. 验证通过后,“游戏客户端”可得到用户信息,根据游戏逻辑可将用户信息传给“游戏服务器”进行验证 3. “游戏服务器 ...

  4. linux 命令 之chomd

    chmod用于改变文件或目录的访问权限.用户用它控制文件或目录的访问权限.该命令有两种用法.一种是包含字母和操作符表达式的文字设定法:另一种是包含数字的数字设定法.  1. 文字设定法 语法:chmo ...

  5. Centos6.4 coll linux 10.2

    由于oracle10g太老了,只怪他娘Oracle生它生的太早了,差点就没赶上新时代(这家伙内心可也有些挺自豪的东东的,人家很有可能跟着它的主要干爹工程师为雅典奥运贡献了门票哩,生逢盛会啊!),较Ce ...

  6. Spark RDD概念学习系列之Spark的算子的作用(十四)

    Spark的算子的作用 首先,关于spark算子的分类,详细见 http://www.cnblogs.com/zlslch/p/5723857.html 1.Transformation 变换/转换算 ...

  7. Java设计模式系列之动态代理模式(转载)

    代理设计模式 定义:为其他对象提供一种代理以控制对这个对象的访问. 动态代理使用 java动态代理机制以巧妙的方式实现了代理模式的设计理念. 代理模式示例代码 public interface Sub ...

  8. iOS学习之触摸事件

    触摸事件 iOS中的事件: 在用户使用app过程中,会产生各种各样的事件.iOS中的事件可以分为3大类型: view的触摸事件处理: 响应者对象: 在iOS中不是任何对象都能处理事件,只有继承了UIR ...

  9. javascript表单(form)序列化

    function serialize(form){ var part =[]; var field = null; var i; var j; var len; var optLen; var opt ...

  10. JQuery学习使用笔记 -- JQuery插件开发

    内容转载自 http://www.css88.com/archives/4821 扩展jQuery插件和方法的作用是非常强大的,它可以节省大量开发时间.这篇文章将概述jQuery插件开发的基本知识,最 ...