POJ 3071 Football(简单 概率DP)

Football

原文链接:http://blog.csdn.net/xuechelingxiao/article/details/38520105

大意:2^n 个球队进行单场淘汰赛,每两只球队之间比赛会有胜负的概率,问最后谁夺冠的概率最大。

思路:简单的概率DP问题,主要是怎么处理哪两个球队比赛的问题。

DP方程为 dp[i][j] = ∑(dp[i-1][j]*dp[i-1][k]*p[j][k]); //dp[i][j]表示第 i 轮的时候,第 j 支队伍赢的概率。、

对于其中位运算,可以用一个二叉树来更直观的理解  (j>>(i-1))^1) 跟 (k>>(i-1)分别表示一个父节点的两个子节点, 当(j>>(i-1))^1) == (k>>(i-1)时,表明两个子节点是竞争关系,胜利者将更新到复接点。

#include <stdio.h>
#include <string.h>

int n;
double p[1000][1000];
double dp[10][1000];

int main()
{
    while(~scanf("%d", &n) && n != -1){
        for(int i = 0; i < (1<<n); ++i){
            for(int j = 0; j < (1<<n); ++j){
                scanf("%lf", &p[i][j]);
            }
        }
        memset(dp, 0, sizeof(dp));

        for(int i = 0; i < (1<<n); ++i){
            dp[0][i] = 1;
        }
        for(int i = 1; i <= n; ++i){
            for(int j = 0; j < (1<<n); ++j){
                for(int k = 0; k < (1<<n); ++k){
                    if(((j>>(i-1))^1) == (k>>(i-1)))
                        dp[i][j] += dp[i-1][k]*dp[i-1][j]*p[j][k];
                }
            }
        }

        double ans = -1;
        int Ans = -1;
        for(int i = 0; i < (1<<n); ++i){
            if(dp[n][i] > ans){
                ans = dp[n][i];
                Ans = i;
            }
        }
        printf("%d\n", Ans+1);
    }

    return 0;
}

POJ 3071 Football(简单 概率DP),布布扣,bubuko.com

时间: 2024-11-17 22:08:05

POJ 3071 Football(简单 概率DP)的相关文章

poj 3071 Football (概率 dp)

链接:poj 3071 题意:有2^n个队,相邻的两两打淘汰赛,n轮后必定会决出冠军, 求最后哪个队夺冠的概率最大 分析:dp[i][j]表示第i轮的时候,第j去支队伍赢的概率 则dp[i][j]的前提就是i-1轮的时候,j是赢的,且第i轮赢了对方 接下来就是找到第i轮的时候,他的可能队手(难点) 所有对手的编号为1-2^n,通过二进制可以发现规律, 若第j队和对手k队在第i轮比赛,那么(j-1)和(k-1)二进制第i位刚好相反, 从i+1位开始所有高位是一样的,可以利用位运算判断是否为对手 状

POJ 3071 Football (概率DP)

概率dp的典型题.用dp[j][i]表示第j个队第i场赢的概率.那么这场要赢就必须前一场赢了而且这一场战胜了可能的对手.这些都好想,关键是怎么找出当前要算的队伍的所有可能的竞争对手?这个用异或来算,从队伍编号的二进制表示中可以看出规律来(从二进制和相关运算里找规律也是一个重要的思考角度). #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<s

POJ 3071 Football:概率dp

题目链接:http://poj.org/problem?id=3071 题意: 给定n,有2^n支队伍参加足球赛. 给你所有的p[i][j],表示队伍i打败队伍j的概率. 淘汰赛制.第一轮(1,2)两队比.(3,4)比.(5,6)比...共进行n轮比赛后产生冠军. 问你冠军最有可能是哪支队伍. 题解: 表示状态: dp[i][j] = probability to win 第i支队伍能够参加第j轮比赛的概率. 找出答案: i of max dp[i][n+1] n轮比赛后,冠军该参加第n+1轮比

POJ 3071 Football 【概率DP】

Football Football Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3734   Accepted: 1908 Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, -, 2n. In each round of the tournament, all teams sti

POJ 3071 Football (动态规划-概率DP)

Football Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2768   Accepted: 1412 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

[ACM] POJ 3071 Football (概率DP)

Football Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2875   Accepted: 1462 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

Aeroplane chess(简单概率dp)

Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six faces with equal probability to face up and the numbers on the faces are 1,2,3,4,5,6). Whe

简单概率DP——hdu4405

题目描述: Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six faces with equal probability to face up and the numbers on the faces are 1,2,3,4,5,6

poj 3744 矩阵加速--概率DP

http://poj.org/problem?id=3744 犯二了,,递推式,矩阵幂什么都会,但是我推得跟别人不一样,,,应该是对矩阵理解问题,,,再看看 #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <iostream> #include <iomanip> #include <cmath> #i