Football 概率DP poj3071
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 2590 | Accepted: 1315 |
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
#include <iostream>
#include <stdio.h>
using namespace std;
double a[<<][<<];
double dp[][<<];
int main()
{
int n,i,j,k;
while(cin>>n)
{
if(n==-)break;
for(i=; i<<<n; i++)
for(j=; j<<<n; j++)
scanf("%lf",&a[i][j]);
for(i=; i<<<n; i++)dp[][i]=;
for(i=;i<=n;i++)
{
for(j=;j<<<n;j++)
{
dp[i][j]=;
int start=((j>>(i-))^)<<(i-);
int num=<<(i-);
for(k=start;k<num+start;k++)
dp[i][j]+=dp[i-][j]*dp[i-][k]*a[j][k];
}
}
double max=,an=;
for(i=;i<<<n;i++)
{
if(dp[n][i]>max)
{
max=dp[n][i];
an=i;
}
}
cout<<an+<<endl;
}
}
Football 概率DP poj3071的更多相关文章
- POJ3071:Football(概率DP)
Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, …, 2 ...
- [poj3071]football概率dp
题意:n支队伍两两进行比赛,求最有可能获得冠军的队伍. 解题关键:概率dp,转移方程:$dp[i][j] + = dp[i][j]*dp[i][k]*p[j][k]$表示第$i$回合$j$获胜的概率 ...
- POJ3071 Football 概率DP 简单
http://poj.org/problem?id=3071 题意:有2^n个队伍,给出每两个队伍之间的胜率,进行每轮淘汰数为队伍数/2的淘汰赛(每次比赛都是相邻两个队伍进行),问哪只队伍成为冠军概率 ...
- poj 3071 Football (概率DP水题)
G - Football Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3071 Football(概率DP)
题目链接 不1Y都对不住看过那么多年的球.dp[i][j]表示i队进入第j轮的概率,此题用0-1<<n表示非常方便. #include <cstdio> #include &l ...
- poj 3071 Football(概率dp)
id=3071">http://poj.org/problem? id=3071 大致题意:有2^n个足球队分成n组打比赛.给出一个矩阵a[][],a[i][j]表示i队赢得j队的概率 ...
- POJ 3071 Football (概率DP)
概率dp的典型题.用dp[j][i]表示第j个队第i场赢的概率.那么这场要赢就必须前一场赢了而且这一场战胜了可能的对手.这些都好想,关键是怎么找出当前要算的队伍的所有可能的竞争对手?这个用异或来算,从 ...
- 动态规划之经典数学期望和概率DP
起因:在一场训练赛上.有这么一题没做出来. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6829 题目大意:有三个人,他们分别有\(X,Y,Z\)块钱 ...
- [转]概率DP总结 by kuangbin
概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/20 ...
随机推荐
- Ext.Msg.alert添加确定按钮
Ext.Msg.alert('成功','成功!!', function(btn){ if(btn!=null{//btn=='ok'||btn=='cancel' ... } });
- [js高手之路]深入浅出webpack教程系列3-配置文件webpack.config.js详解(下)
本文继续接着上文,继续写下webpack.config.js的其他配置用法. 一.把两个文件打包成一个,entry怎么配置? 在上文中的webpack.dev.config.js中,用数组配置entr ...
- Linaro系统获取root权限方法
在Zedboard上根据教程安装Linaro Ubuntu后出现一只无法获取Root权限,导致无法挂载U盘等问题. 具体体现在sudo -s命令之后,出现如sudo:must be setuid ro ...
- 算法学习:Pac-Man的简单对抗
Pacman项目是加州大学伯克利分校提供的一个可视化的AI学习平台.其主体利用python完成.该项目提供了丰富的说明文档,以及预先实现了一些简单的算法供参考各接口的使用. http://ai.ber ...
- 201521123022 《Java程序设计》 第六周学习总结
1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 2. 书面作业 Q1.clone方法 Q1.1 Objec ...
- 201521123100 《Java程序设计》第3周学习总结
1. 本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识组织起来.请使用纸笔或者下面的工具画出本周学习到的知识点.截图或者拍照上传. 2. 书面作 ...
- 201521123047 《Java学习笔记》第二周学习总结
1. 本周学习总结 -知道并了解到浮点数的误差关系,懂得运java.math.BigDecimal来进行浮点数的精确计算 -对于"="与"=="的区分 -字符串 ...
- 201521123114《Java程序设计》第1周学习总结
1. 本周学习总结 java语言具有:简约且简单,平台无关性,面向对象,多线程.分布性.高性能.健壮性等特点. 2. 书面作业 1.为什么java程序可以跨平台运行?执行java程序的步骤是什么? J ...
- python类型转换、数值操作(收藏)
最近学习python语言,碰到数据类型间的转换问题.看到一篇文章总结的挺详细,收藏之备用. 类型转换 代码 1 函数 描述 2 int(x [,base ...
- Python[小甲鱼003小插曲之变量和字符串]
>>>teacher = 3 >>>teacher 3 #在定义了一个变量后可以之间输入整个变量即可访问这个变量. >>> teache ...