CF26D Tickets 期望,概率复习

· · 题解

说是复习 其实这道题的知识点我没学过

核心 我是看这篇博客学会的

Firstly,转化题面

现在在(k,0)的位置

每次可以向上走一步或向右走一步

即从(a,b)可以到(a+1,b)或(a,b+1)

要求不能过f(x)=x

求走到(n+k,m)的方法数P

Secondly,方法

如图 从B(k,0)走到A(n+k,m)

先不考虑不能过f(x)=x

方法数易得:

C_{n+m}^{m}

然后再算过了的 相减就得P

我们找C点

可得$c(-1,k+1)

只要 B到A是经过了f(x)=x的

那么一定有一条对应的C到A的路径

证明:

如果B到A的路径过f(x)=x

那么B到A的路径一定过f(x)=x+1或有点在f(x)=x+1上

如图 D点一定存在

定义g(a,b)为从a点到b点的方法数

则g(c,d)=g(b,d)

一定有g(d,a)=g(d,a)

所以只要 B到A是经过了f(x)=x的

那么一定有一条对应的C到A的路径

现在 就可以得出

P=C_{n+m}^{m}-g(c,a)=C_{n+m}^{m}-C_{n+m}^{m-k-1}

再除以方案总数 化简可得

1-\frac{\displaystyle\prod_{i=m-k}^{m}i}{\displaystyle\prod_{j=n+1}^{n+k+1}j}

Code

#include <map>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define reg register int
#define isdigit(x) ('0' <= (x)&&(x) <= '9')
template<typename T>
inline T Read(T Type)
{
    T x = 0,f = 1;
    char a = getchar();
    while(!isdigit(a)) {if(a == '-') f = -1;a = getchar();}
    while(isdigit(a)) {x = (x << 1) + (x << 3) + (a ^ '0');a = getchar();}
    return x * f;
}
double ans = 1.0;
int main()
{
    int n = Read(1),m = Read(1),k = Read(1);
    if(n + k >= m)
    {
        for(reg i = 1;i <= k + 1;i++)
            ans *= (double)(i + m - k - 1) / (n + i);
        printf("%.5lf",1.0 - ans);
    } else printf("0");
    return 0;
}