POJ 3071-Football(可能性dp)
| 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)的更多相关文章
- 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>
链接:http://poj.org/problem?id=3071 题意: 有 2^n 支足球队,编号 1~2^n,现在给出每支球队打败其他球队的概率,问哪只球队取得冠军的概率最大? 思路: 设dp[ ...
- POJ 3071 Football:概率dp
题目链接:http://poj.org/problem?id=3071 题意: 给定n,有2^n支队伍参加足球赛. 给你所有的p[i][j],表示队伍i打败队伍j的概率. 淘汰赛制.第一轮(1,2)两 ...
- POJ 3071 Football 【概率DP】
Football Football Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3734 Accepted: 1908 ...
- POJ 3071 Football (概率DP)
概率dp的典型题.用dp[j][i]表示第j个队第i场赢的概率.那么这场要赢就必须前一场赢了而且这一场战胜了可能的对手.这些都好想,关键是怎么找出当前要算的队伍的所有可能的竞争对手?这个用异或来算,从 ...
- POJ 3071 Football
很久以前就见过的...最基本的概率DP...除法配合位运算可以很容易的判断下一场要和谁比. from——Dinic算法 Football Time ...
- poj 3071 Football(线段树+概率)
Football Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2801 Accepted: 1428 Descript ...
随机推荐
- apache本地多域配置(wampserver本地多域配置)
当我们在当地发展.通常在浏览器中输入 http://localhost/项目目录名 测试Web文件,你有没有想过在本地浏览器中,输入自己设定的名字进入项目目录,名相关的问题. 比方我想配置一个主域名w ...
- sgu128snack
按我的理解大概说下题意: 有非常多个点,最多一万个,告诉你它们的坐标.如今须要构造一条闭合线.这个闭合线满足下面六点: 1必须是闭合的. 2必须用到全部的点. 3构造的线段之间若成角,则必须是90度. ...
- Visual Studio Team Services使用教程--Readers tfs组成员添加
- mysql大写和小写问题
曾经做企业项目的时候,用的都是oracle数据库,在新公司项目用的是mysql,有关mysql大写和小写的问题 1 windows下默认mysql是不区分大写和小写的,要想让其支持大写和小写.更改 ...
- mahout源码KMeansDriver分析之五CIMapper初探
接着上篇,继续分析代码.下面就到了MR的循环了,这里MR应该算是比较好理解的,重点是退出循环的条件设置,即如何判断前后两次中心点误差小于给定阈值. 首先,while循环: while (iterati ...
- LeetCode 48 Anagrams
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...
- Redis安装与基本配置(转)
一.下载与安装 wget http://download.redis.io/releases/redis-3.0.0.tar.gz tar -zxvf redis-3.0.0.tar.gz -c /u ...
- Java静态字段(属性、方法、类别)
假设域被定义为static,那么每个类中仅仅有一个这种域.作为对照,每个对象对于全部的实例域却都有自己的一份拷贝. 比如,假定须要给每个雇员赋予唯一的标识码. 这里给Employee类加入一个实例域i ...
- VisualSVN
Symptoms When performing a large commit to VisualSVN Server over the HTTPS protocol, the Subversion ...
- CentOS 7 下安装 LEMP 服务(nginx、MariaDB/MySQL 和 php)
原文 CentOS 7 下安装 LEMP 服务(nginx.MariaDB/MySQL 和 php) LEMP 组合包是一款日益流行的网站服务组合软件包,在许多生产环境中的核心网站服务上起着强有力的作 ...