luogu P3978 [TJOI2015]概率论
看着就是要打表找规律
使用以下代码
for(int i=3;i<=20;i++)
{
int a1=0,a2=0;
for(int j=1;j<i;j++)
{
for(int k=0;k<i;k++)
for(int l=0;l<=j;l++)
f[i][j]+=f[k][l]*f[i-k-1][j-l];
a2+=f[i][j],a1+=f[i][j]*j;
}
}
可以打出表
n 树总数 叶子总数
1 1 1
2 2 2
3 5 6
4 14 20
5 42 70
6 132 252
7 429 924
...
设树总数为f_n,叶子总数为g_n,我们可以发现f_n=\frac {\binom{2n}{n}} {n+1}g_n=nf_{n-1}
我们要求的期望就是\frac{g_n}{f_n}=\frac{nf_{n-1}}{f_n}=\frac{n \frac {\binom{2n-2}{n-1}} {n}}{\frac {\binom{2n}{n}} {n+1}}
=\frac{\binom{2n-2}{n-1}}{\binom{2n}{n}}*(n+1)=...=\frac{n(n+1)}{2(2n-1)}
没了
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#define LL long long
#define il inline
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
il LL rd()
{
re LL x=0,w=1;re char ch;
while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*w;
}
double n;
int main()
{
n=rd();
printf("%.10lf\n",n*(n+1)/2/(2*n-1));
return 0;
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!