当前位置:网站首页>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 堆区大小设置
- Policy Center > Misrepresentation
- 有意思的鼠标指针交互探究
- MySQL proxy middleware atlas installation and configuration
- MySQL master-slave configuration
- KDD 2022 | how far are we from the general pre training recommendation model? Universal sequence representation learning model unisrec for recommender system
- 2020蓝桥杯国赛B组-搬砖-(贪心排序+01背包)
- RT-Thread 堆區大小設置
- Bidding announcement: remote disaster recovery project of Shenzhen Finance Bureau database
- 【Unity UGUI】ScrollRect 动态缩放格子大小,自动定位到中间的格子
猜你喜欢
容联云首发基于统信UOS的Rphone,打造国产化联络中心新生态
备战数学建模33-灰色预测模型2
抖快B为啥做不好综艺
电子烟强制性国家标准GB 41700-2022发布 2022年10月1日起实施
Policy Center > Device and Network Abuse
RT-Thread 堆區大小設置
备战数学建模34-BP神经网络预测2
Policy Center > Google Play‘s Target API Level Policy
[unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid
Policy Center-User Data
随机推荐
优惠券种类那么多,先区分清楚再薅羊毛!
微信表情符号写入判决书,你发的OK、炸弹都可能成为“呈堂证供”
Bidding announcement: Tianjin housing provident fund management center database all-in-one machine and database software project (budget: 6.45 million)
荣盛生物冲刺科创板:拟募资12.5亿 年营收2.6亿
Policy Center > Malware > Malware
Half year inventory of new consumption in 2022: the industry is cold, but these nine tracks still attract gold
Mysql8 error: error 1410 (42000): you are not allowed to create a user with grant solution
什么是XR扩展现实,XR云串流平台有哪些
Carry two load balancing notes and find them in the future
2022蓝桥杯国赛B组-2022-(01背包求方案数)
2020蓝桥杯国赛B组-搬砖-(贪心排序+01背包)
Log4j2 进阶使用
搬运两个负载均衡的笔记,日后省的找
BC1.2 PD协议
Interpretation of gaussdb's innovative features: partial result cache accelerates operators by caching intermediate results
flink sql cdc 同步sqlserver 报错什么原因啊
CVPR 2022 - Tesla AI proposed: generalized pedestrian re recognition based on graph sampling depth metric learning
Policy Center-Permissions and APIs that Access Sensitive Information
边缘计算平台如何助力物联网发展
今晚19:00知识赋能第2期直播丨OpenHarmony智能家居项目之控制面板界面设计