luogu#P3978. [TJOI2015] 概率论

    ID: 8006 Type: RemoteJudge 1000ms 125MiB Tried: 9 Accepted: 7 Difficulty: 8 Uploaded By: Tags>递推2015各省省选Special Judge卡特兰Catalan生成函数期望天津

[TJOI2015] 概率论

Problem Description

To boost her IQ, ZJY started studying probability theory. One day, she came up with this question: among all non-isomorphic rooted binary trees with nn nodes, chosen uniformly at random, what is the expected number of leaf nodes?

The pseudocode to check whether two trees are isomorphic is as follows:

$$\def\arraystretch{1.2} \begin{array}{ll} \hline \textbf{Algorithm 1}&\text{Check}(T1,T2) \\ \hline 1&\textbf{Require: }\text{ nodes }T1,T2\text{ of the two trees}\\ 2&\qquad\textbf{if}\ \ T1=\text{null}\textbf{ or }T2=\text{null}\textbf{ then }\\ 3&\qquad\qquad\textbf{return}\ \ T1=\text{null}\textbf{ and }T2=\text{null}\\ 4&\qquad\textbf{else}\\ 5&\qquad\qquad\textbf{return}\ \text{Check}(T1\to\mathit{leftson},T2\to\mathit{leftson}) \\ & \qquad\qquad\qquad \textbf{ and }\text{Check}(T1\to\mathit{rightson},T2\to\mathit{rightson})\\ 6&\qquad\textbf{endif}\\ \hline \end{array}$$

Input Format

Input a positive integer nn, the number of nodes in the rooted tree.

Output Format

Output the expected number of leaf nodes of the tree. The error must be less than 10910^{-9}.

1
1.000000000
3
1.200000000

Hint

Constraints

  • For 30%30\% of the testdata, 1n101 \le n \le 10.
  • For 70%70\% of the testdata, 1n1001 \le n \le 100.
  • For 100%100\% of the testdata, 1n1091 \le n \le 10^9.

Translated by ChatGPT 5