poj3071 Football(概率dp)

题目链接

分析:
实际上题目中已经给出了计算方式

P(2wins)=P(2beats1)P(3beats4)P(2beats3)+P(2beats1)P(4beats3)P(2beats4) P ( 2 w i n s ) = P ( 2 b e a t s 1 ) P ( 3 b e a t s 4 ) P ( 2 b e a t s 3 ) + P ( 2 b e a t s 1 ) P ( 4 b e a t s 3 ) P ( 2 b e a t s 4 )
=p2,1p3,4p2,3+p2,1p4,3p2,4 = p 2 , 1 p 3 , 4 p 2 , 3 + p 2 , 1 p 4 , 3 p 2 , 4
=0.90.60.4+0.90.40.5=0.396 = 0.9 · 0.6 · 0.4 + 0.9 · 0.4 · 0.5 = 0.396

f[i][j] f [ i ] [ j ] ,表示第 i i 轮,j队获胜的概率
i i 轮,比赛会在长度为2i的序列内进行
2i1 2 i − 1 支队伍会与后 2i1 2 i − 1 支队伍比赛

f[i][x]=f[i1][x]f[i1][y]p[x][y[ f [ i ] [ x ] = ∑ f [ i − 1 ] [ x ] ∗ f [ i − 1 ] [ y ] ∗ p [ x ] [ y [
直接转移即可

tip

不要忘了初始化

#include<cstdio>
#include<cstring>
#include<iostream>

using namespace std;

const double eps=1e-8;
const int N=130;
int n;
double p[N][N],f[10][N];

int main()
{
    while (scanf("%d",&n)!=EOF&&n!=-1) {
        int tot=1<<n;
        for (int i=1;i<=n;i++)
            for (int j=1;j<=tot;j++) f[i][j]=0.0;

        for (int i=1;i<=tot;i++)
            for (int j=1;j<=tot;j++)
                scanf("%lf",&p[i][j]);
        for (int i=1;i<=tot;i++) f[1][i]=p[i][(i&1)? i+1:i-1];
        for (int i=2;i<=n;i++) {
            int m=1<<(i-1);
            for (int j=1;j<=tot;j+=(1<<i)) 
                for (int k=j;k<j+m;k++)
                    for (int s=j+m;s<j+2*m;s++) {
                        f[i][k]+=f[i-1][k]*f[i-1][s]*p[k][s];
                        f[i][s]+=f[i-1][s]*f[i-1][k]*p[s][k];
                    }
        }
        int ans;
        double mx=0;
        for (int i=1;i<=tot;i++) 
            if (f[n][i]-mx>eps) mx=f[n][i],ans=i;
        printf("%d\n",ans); 
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值