当前位置:网站首页>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;
}
边栏推荐
- Relatively easy to understand PID understanding
- [QT] QT cannot find a solution to the compiler using msvc2017
- [QT] solve the problem that QT MSVC 2017 cannot compile
- ADO. Net SqlDataAdapter object
- PostgreSQL source code (58) tuple splicing heap_ form_ Tuple analysis
- [cmake] cmake configuration in QT Creator
- Windows 7 安装MYSQL 错误:1067
- Jielizhi, production line assembly link [chapter]
- kubernetes资源对象介绍及常用命令(三)
- 写给当前及未来博士研究生一些建议整理分享
猜你喜欢

起床困难综合症(按位贪心)
![[cmake] cmake configuration in QT Creator](/img/e3/1cf76f88eaddb5d32184523dfb049c.png)
[cmake] cmake configuration in QT Creator

Selectively inhibiting learning bias for active sampling

Material Design组件 - 使用BottomSheet展现扩展内容(一)

Redis RDB snapshot

Digital transformation has a long way to go, so how to take the key first step

Key points of security agreement

【CMake】Qt creator 里面的 cmake 配置
![[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

kubernetes资源对象介绍及常用命令(三)
随机推荐
TS initial use, TS type
PyTorch学习记录
vue 强制清理浏览器缓存
What are the common types of points mall games?
Use pair to do unordered_ Key value of map
Windows10 install WSL (I) (wslregisterdistribution error)
- Oui. Env. Fichier XXX, avec constante, mais non spécifié
The best smart home open source system in 2022: introduction to Alexa, home assistant and homekit ecosystem
Asp .NetCore 微信订阅号自动回复之文本篇
Use the htaccess file to prohibit the script execution permission in the directory
【模板】自适应辛普森积分
[QT] test whether QT can connect to the database
LDR6035智能蓝牙音响可充可放(5.9.12.15.20V)快充快放设备充电
mysql:insert ignore、insert和replace区别
How to realize parallel replication in MySQL replication
牛客-练习赛101-推理小丑
ADO. Net SqlConnection object usage summary
[Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler
ConcurrentSkipListMap——跳表原理
起床困难综合症(按位贪心)