当前位置:网站首页>Niuke: how many different binary search trees are there
Niuke: how many different binary search trees are there
2022-06-30 16:39:00 【lsgoose】


I made it very clear on Li Kou , Interesting derivation :
First , set up F(i,n) Express n Length of the sequence with i The number of binary search trees divided for the root node ,G(n) Length n The number of binary search trees of the sequence of , Obviously :

And obviously ,F(i, n) In fact, the number of can be determined by two subtrees G Obtained , As shown below :

And then we derive G Recursive expression of :

The code is as follows :
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> G(n+1);
G[0]=G[1]=1;
for(int i=2;i<=n;++i){
for(int j=0;j<=i;++j){
G[i]+=G[j-1]*G[i-j];
}
}
cout<<G[n];
return 0;
}
边栏推荐
- 构建适合组织的云原生可观测性能力
- RT-Thread 堆區大小設置
- 更多龙蜥自研特性!生产可用的 Anolis OS 8.6 正式发布
- MySQL8.0开启远程连接权限的方法步骤
- Distributed machine learning: model average Ma and elastic average easgd (pyspark)
- 24:第三章:开发通行证服务:7:自定义异常(来表征程序中出现的错误);创建GraceExceptionHandler来全局统一处理异常(根据异常信息,构建对应的API统一返回对象的,JSON数据);
- Which direction should college students choose to find jobs after graduation?
- 360 digital, ant group, etc. were selected as member units of the "business security promotion plan" of the Chinese Academy of Communications
- RT thread heap size Setting
- Asp. NETCORE uses cache and AOP to prevent repeated commit
猜你喜欢

Li Zexiang, a legendary Chinese professor, is making unicorns in batches

7 月 2 日邀你来TD Hero 线上发布会

After 15 years of working on 21 types of hardware, where is Google?

几百行代码实现一个 JSON 解析器

备战数学建模35-时间序列预测模型

Anaconda下安装Jupyter notebook

Policy Center > Device and Network Abuse

更多龙蜥自研特性!生产可用的 Anolis OS 8.6 正式发布
![[unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid](/img/c9/ff22a30a638b5d9743d39e22ead647.png)
[unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid

Distributed machine learning: model average Ma and elastic average easgd (pyspark)
随机推荐
Carry two load balancing notes and find them in the future
After 15 years of working on 21 types of hardware, where is Google?
Bidding announcement: Tianjin housing provident fund management center database all-in-one machine and database software project (budget: 6.45 million)
Siyuan notes: can you provide shortcut keys for folding all titles on the page?
MySQL master-slave configuration
搬运两个负载均衡的笔记,日后省的找
优惠券种类那么多,先区分清楚再薅羊毛!
有意思的鼠标指针交互探究
How to get the preferential activities for stock account opening? Is online account opening safe?
云化XR,如何助力产业升级
【Verilog基础】十进制负数的八进制、十六进制表示
Build cloud native observability capability suitable for organizations
Compulsory national standard for electronic cigarette GB 41700-2022 issued and implemented on October 1, 2022
Cesium-1.72 learning (earth model creation online offline tile)
中航无人机科创板上市:市值385亿 拳头产品是翼龙无人机
In depth analysis of the core code of the gadgetinspector
Under the pressure of technology, you can quickly get started with eth smart contract development, which will take you into the ETH world
flink sql cdc 同步sqlserver 报错什么原因啊
Asp. NETCORE uses cache and AOP to prevent repeated commit
容联云首发基于统信UOS的Rphone,打造国产化联络中心新生态