https://www.luogu.org/problem/P3830
分析
第一问比较简单,从平均的概念出发,每次扩展我们增加$Average_{i-1}+2$的总深度
所以有$Average_i =\frac{Average_{i-1}*(i-1)+Average_{i-1}+2}{i}$
等于$Average_i =Average_{i-1}+\frac{2}{i}$
第二问作为LaTeX菜菜不想打那么多公示了 挂个网址⑧
https://www.luogu.org/blog/contributation/solution-p3830
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include <iostream> #include <cstdio> using namespace std; const int N=110; int q,n; double f[N][N],ans; int main() { scanf("%d%d",&q,&n); if (q==1) { for (int i=2;i<=n;i++) f[i][0]=f[i-1][0]+2.0/i; printf("%.6lf",f[n][0]); } else { for (int i=1;i<=n;i++) f[i][0]=1; for (int i=2;i<=n;i++) for (int j=1;j<i;j++) for (int k=1;k<i;k++) f[i][j]+=1.0*(f[k][j-1]+f[i-k][j-1]-f[k][j-1]*f[i-k][j-1])/(i-1); for (int i=1;i<=n;i++) ans+=f[n][i]; printf("%.6lf",ans); } }