当前位置:网站首页>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;
}
边栏推荐
- 记录一下大文件上传偶然成功偶然失败问题
- Applet form verification encapsulation
- Write some suggestions to current and future doctoral students to sort out and share
- Redis AOF log
- .env.xxx 文件,加了常量,却undefined
- ERP项目施行计划的目的是什么?
- 【C#】依赖注入及Autofac
- Is it safe to buy funds on Great Wall Securities?
- 学成在线案例实战
- Door level modeling - after class exercises
猜你喜欢

深度学习 | 三个概念:Epoch, Batch, Iteration

Door level modeling - after class exercises

Using uni simple router, dynamically pass parameters typeerror: cannot convert undefined or null to object

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

USB-IF协会与各种接口的由来

【QT】QtCreator卸载与安装(非正常状态)

Use pair to do unordered_ Key value of map

【QT】测试Qt是否能连接上数据库

Review data desensitization system

Graduation season is both a farewell and a new beginning
随机推荐
Is it safe to choose mobile phone for stock trading account opening in Beijing?
PostgreSQL notes (10) dynamically execute syntax parsing process
[QT] solve the problem that QT MSVC 2017 cannot compile
【.Net Core】程序相关各种全局文件
Using SqlCommand objects in code
电商RPA机器人,助力品牌电商抢立流量高点
【CMake】Qt creator 里面的 cmake 配置
vs2015 AdminDeployment.xml
Pytorch learning record
ConcurrentSkipListMap——跳表原理
Iota in golang
Material Design组件 - 使用BottomSheet展现扩展内容(一)
ADO. Net SqlDataAdapter object
Concurrentskiplistmap -- principle of table skipping
Redis RDB snapshot
启牛学院开户安全的吗?开户怎么开?
PyCharm调用matplotlib绘图时图像弹出问题怎么解决
mysql之B tree 以及 B+tree
TS initial use, TS type
PyTorch学习记录