当前位置:网站首页>Leetcode 96 différents arbres de recherche binaires
Leetcode 96 différents arbres de recherche binaires
2022-07-02 00:00:00 【Neige nocturne à Yingtai】
leetcode96:Différents arbres de recherche binaires
Description du sujet
Pour vous donner un entier n ,Je vous en prie. n Les noeuds sont composés et les valeurs des noeuds sont de 1 À n Différents Arbre de recherche binaire Combien de?Renvoie le nombre d'arbres de recherche binaires qui répondent à l'intention du sujet.
Exemple d'entrée / sortie

Entrée:n = 3
Produits:5
Entrée:n = 1
Produits:1
Algorithme I:Utiliser la planification dynamique
//Définition de l'arbre de recherche binaire:Si son Sous - arbre gauche n'est pas vide,La valeur de tous les noeuds du sous - arbre gauche est inférieure à son noeud racine,Si son Sous - arbre droit n'est pas vide,La valeur de tous les noeuds du sous - arbre droit est supérieure à la valeur de son noeud racine
//Ses sous - arbres gauche et droit sont également des arbres de recherche binaires
int numTrees(int n)
{
//Créer un tableau de planification dynamique
vector<int>dp(n+1,0);
//Définir les conditions initiales
dp[0]=1;
dp[1]=1;
//Définir l'équation de conversion
for(int i=2;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
dp[i]+=dp[j-1]*dp[i-j];
}
}
return dp[n];
}
Algorithme 2:Utiliser la définition du nombre de glandes
//Nombre de catalans
int numTrees2(int n)
{
long long c=1;
for(int i=0;i<n;i++)
{
c=c*2*(2*i+1)/(i+2);
}
return (int)c;
}
边栏推荐
- 正则表达式收集
- 【CMake】Qt creator 里面的 cmake 配置
- 华为HMS Core携手超图为三维GIS注入新动能
- Reproduction process and problems of analog transformer (ICLR 2022 Spotlight)
- Chapter 6 data flow modeling
- 2021 robocom world robot developer competition - preliminary competition of higher vocational group
- [cmake] cmake configuration in QT Creator
- leetcode96不同的二叉搜索树
- Relatively easy to understand PID understanding
- RPA tutorial 01: Excel automation from introduction to practice
猜你喜欢

Windows10 install WSL (I) (wslregisterdistribution error)

RPA教程01:EXCEL自动化从入门到实操
![[Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler](/img/35/e458fd437a0bed4bace2d6d65c9ec8.png)
[Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler
![[embedded system course design] a single key controls the LED light](/img/c9/076618208bbab0b95faa5a7e644a07.png)
[embedded system course design] a single key controls the LED light

.env.xxx 文件,加了常量,却undefined
Linux CentOS7安装Oracle11g的超完美新手教程

S32Kxxx bootloader之UDS bootloader

PyTorch学习记录

Overview of edge calculation

关联性——组内相关系数
随机推荐
Redis AOF log
ADO. Net SqlCommand object
Linux CentOS7安装Oracle11g的超完美新手教程
门级建模—课后习题
多表操作-一对一,一对多与多对多
LDR6035智能蓝牙音响可对手机设备持续充放电方案
Jielizhi, production line assembly link [chapter]
【QT】對於Qt MSVC 2017無法編譯的問題解决
MySQL Replication中并行复制怎么实现
ADO.NET之sqlCommand对象
北京炒股开户选择手机办理安全吗?
SecurityUtils. getSubject(). How to solve the problem that getprincipal() is null
Windows 7 安装MYSQL 错误:1067
Regular expression collection
写给当前及未来博士研究生一些建议整理分享
MySQL: the difference between insert ignore, insert and replace
使用VB.net将PNG图片转成icon类型图标文件
Write some suggestions to current and future doctoral students to sort out and share
RPA教程01:EXCEL自动化从入门到实操
Applet form verification encapsulation