POJ3071:Football(概率DP)
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
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.
题意:有2^n支队伍进行比赛,每行给出这支队伍打败各支队伍的几率,求出那支队伍获胜几率最大
思路:
概率DP,递推式:dp[i][j]=sigma(dp[i-1][j]*p[j][k]*dp[i-1][k]),然后判断两支队伍是否相邻
dp[i][j]代表第i轮中,第j支队伍存活的几率
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; double a[150][150],dp[150][150]; int main()
{
int n,m,i,j,k,ans;
while(~scanf("%d",&n),n+1)
{
m = 1<<n;
for(i = 0; i<m; i++)
for(j = 0; j<m; j++)
scanf("%lf",&a[i][j]);
memset(dp,0,sizeof(dp));
for(i = 0; i<m; i++)//一开始所有队伍都存活
dp[0][i] = 1;
for(i = 1; i<=n; i++)
for(j = 0; j<m; j++)
for(k = 0; k<m; k++)
{
int p = k>>(i-1),q = j>>(i-1);//判断是否相邻
if(p%2)
{
p--;
if(p==q)//判断p前进或后退以为,p==q的话证明他们是相邻的,进行比赛
dp[i][j] += dp[i-1][j]*dp[i-1][k]*a[j][k];//j存活,k存活,j打败k
}
else
{
p++;
if(p==q)
dp[i][j] += dp[i-1][j]*dp[i-1][k]*a[j][k];
}
}
ans = 0;
for(i = 0; i<m; i++)//找最大
{
if(dp[n][ans]<dp[n][i])
ans = i;
}
printf("%d\n",ans+1);
} return 0;
}
POJ3071:Football(概率DP)的更多相关文章
- [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的淘汰赛(每次比赛都是相邻两个队伍进行),问哪只队伍成为冠军概率 ...
- Football 概率DP poj3071
Footbal ...
- poj 3071 Football (概率DP水题)
G - Football Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- poj3071之概率DP
Football Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2667 Accepted: 1361 Descript ...
- POJ 3071 Football(概率DP)
题目链接 不1Y都对不住看过那么多年的球.dp[i][j]表示i队进入第j轮的概率,此题用0-1<<n表示非常方便. #include <cstdio> #include &l ...
- poj3071 Football(概率dp)
poj3071 Football 题意:有2^n支球队比赛,每次和相邻的球队踢,两两淘汰,给定任意两支球队相互踢赢的概率,求最后哪只球队最可能夺冠. 我们可以十分显然(大雾)地列出转移方程(设$f[ ...
- 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场赢的概率.那么这场要赢就必须前一场赢了而且这一场战胜了可能的对手.这些都好想,关键是怎么找出当前要算的队伍的所有可能的竞争对手?这个用异或来算,从 ...
随机推荐
- pyqt tabWidget例子学习1
from PyQt4 import QtGui from PyQt4 import QtCore from PyQt4.QtCore import pyqtSlot,SIGNAL,SLOT impor ...
- hdu3397 Sequence operation
感觉自己好像搞定了一个不得了得题呢.. 对于这种区间性质合并的线段树,对于每个节点保存一下当前区间内1的个数,左右边界相邻的1个的个数与0的个数,还有当前区间最大连续的1和0的个数. 合并的时候的细节 ...
- Bin & Jing in wonderland(概率,组合数学)
Problem 2103 Bin & Jing in wonderland Accept: 201 Submit: 1048 Time Limit: 1000 mSec Memor ...
- Bootstrap在线编辑器简单分享
Bootstrap 已经使响应式网站开发变得简单很多. 但是如果你不必手动写全部代码,事情会如何呢? 如果你可以自由地选择你想要使用的Bootstrap 组件.并可以把它们拖拽到画布中,事情会如何呢? ...
- SpringMVC的@ResponseBody返回JSON,中文乱码问题的解决.
SpringMVC的@ResponseBody,返回json,如果有中文显示乱码的解决办法. 在SpringMVC的配置文件中 <bean class="org.springframe ...
- Error creating bean with name 'memcachedClient'...java.lang.OutOfMemoryError
1,Tomcat启动报错例如以下: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating ...
- winform窗体中查找控件
private RichTextBox FindControl() { RichTextBox ret = null; try { ...
- C#线程池ThreadPool的理解
在多线程编程中,线程的创建和销毁是非常消耗系统资源的,因此,C#引入了池的概念,类似的还有数据库连接池,这样,维护一个池,池内维护的一些线程,需要的时候从池中取出来,不需要的时候放回去,这样就避免了重 ...
- ElasticSearch入门知识扫盲
ElasticSearch 入门介绍 tags: 第三方 lucene [toc] 1. what Elastic Search(ES)是什么 全文检索和lucene 全文检索 优点:高效,准确,分词 ...
- Js 日期处理
Js获取当前日期时间 var myDate = new Date(); myDate.getFullYear(); //获取完整的年份(4位,1970-????) 2014myDate.get ...