---
id: 2000
title: "P3978:「TJOI2015」概率论 - 题解"
slug: p3978-tjoi2015-probability-theory
lang: zh
date: 2020-02-08T10:06:18
date_gmt: 2020-02-08T02:06:18
modified: 2023-11-11T14:49:57
status: publish
password_protected: false
category: { name: Olympiad in Informatics, slug: oi }
tags: [OI, 生成函数]
original_url: https://kalorona.com/oi/p3978tjoi2015概率论-题解/
archived: 2026-11-27
editor: classic
media: []
archive_notes:
  - "Body headings were <h1> in the original; demoted to level 2 so the page title is the only h1."
  - "The trailing &nbsp; after the last code block (an empty paragraph on the live page) was dropped."
comments: []
---

## 推导思路

第一次坐到这种类型的题，社会社会（抱拳）。

先考虑怎么算分母：如果有 $f_i$ 代表大小为 $i$ 的树的种类数，那么可以显然得到 $f_i = \sum_{j = 0}^{n - 1} f_j f_{n - j - 1}$。得到这一步之后，分治 FFT？不，数据范围到达了惊人的 $10^9$，所以分治 FFT 显然不现实。我们可以继续推：

<!--more-->

$$
\begin{aligned} F(x) &= 1 + xF^2(x), x \in [0, 1) \\ &= \frac{1 \pm \sqrt{1 - 4x}}{2x} = \frac{1 - \sqrt{1 - 4x}}{2x} \end{aligned}
$$

看不出什么，我们继续用广义二项式进行展开：

$$
\begin{aligned} F(x) &= \frac{1 - \sqrt{1 - 4x}}{2x} \\ &= \frac{1 - (1 - 4x)^{\frac{1}{2}}}{2x} = \frac{1 - \sum_{i = 0}^{\infty} (-1)^i {\frac{1}{2} \choose i} (4x)^i}{2x} \\ &= \frac{1}{2x}(1 - \sum_{i = 0}^{\infty} (-4)^i {\frac{1}{2} \choose i} x^i) \\ &= \frac{1}{2x} - \sum_{i = 0}^{\infty} (-4)^i {\frac{1}{2} \choose i} x^{i - 1} = \frac{1}{2x} - (\frac{1}{2x} + \sum_{i = 1}^\infty (-4)^i {\frac{1}{2} \choose i} x^{i - 1}) \\ &= \sum_{i = 0}^\infty (-4)^{i + 1} \frac{\prod_{j = 0}^{i + 1}(\frac{1}{2} + i)}{(i + 1)!} x^{i} \end{aligned}
$$

再往下展开就发现系数是卡特兰数，然后就可以直接代公式算就行了。

## 代码

```cpp
// P3978.cpp
#include <bits/stdc++.h>

using namespace std;

int n;

int main()
{
    scanf("%d", &n);
    printf("%.10lf\n", 1.0 * n * (n + 1) / double(2.0 * (2.0 * n - 1)));
    return 0;
}
```
