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 ...
随机推荐
- web安全普及:通俗易懂,如何让网站变得更安全?以实例来讲述网站入侵原理及防护。
本篇以我自己的网站[http://www.1996v.com]为例来通俗易懂的讲述如何防止网站被入侵,如何让网站更安全. 要想足够安全,首先得知道其中的道理. 本文例子通俗易懂,从"破解网站 ...
- 利用Google浏览器调试js代码
1.js有两种引入方式,外链和内嵌: 内嵌在浏览中直接调试,外链要在断点处写debugger; 示例代码: <!DOCTYPE html> <html lang="en&q ...
- 广度优先搜索(BFS)——迷宫的最短路径
宽度优先搜索按照距开始状态由近到远的顺序进行搜索,因此可以很容易的用来求最短路径,最少操作之类问题的答案. 宽度优先搜索介绍(一篇不错的文章). 题目描述: 给定一个大小为N*M的迷宫.迷宫有通道和墙 ...
- github如何添加ssh
1.运行git Bash 输入如下命令: $ cd ~/.ssh $ ls 输入这2个命令 ,我们可以看到 id_rsa.pub 或 id_dsa.pub 这2个文件已经存在了,id_rsa 是私钥, ...
- [js高手之路]深入浅出webpack教程系列9-打包图片(file-loader)用法
我们还是接着上文继续,本文我们要讲的是图片资源的打包,图片在静态排版中,经常出现的两个位置是css通过background引入背景,还有一种就是在html模板文件中用img标签引入的方式,如果要在we ...
- 教你自己搭建linux邮箱服务器
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt290 现在网络中流行的电子邮件系统主要有Microsoft Exchange ...
- 关于"设计模式“
夜深了,人静了,该写点儿东西了.这是第一篇博客,写点儿对设计模式的粗浅理解吧. 什么是设计模式? 上学那会儿初次听到这个名字一点儿概念都没有,不知道它是用来干嘛的,感觉听上去挺抽象的一个东西. 工 ...
- 排序--SelectionSort 选择排序
选择排序 no implementation 选择排序(Selection sort)是一种简单直观的排序算法.它的工作原理是每一次从待排序的元素中中选出最小(或最大)的一个元素,存放在序列的起始位置 ...
- 联合线程(案例顾客买蛋糕 :使用join()方法)
运行效果图:
- 201521123062《Java程序设计》第7周学习总结
1. 本周学习总结 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 源代码如下: public boolean contains(Object ...